Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try avoiding unnecessary copy constructions #60

Open
SchrodingerZhu opened this issue Dec 9, 2019 · 0 comments
Open

Try avoiding unnecessary copy constructions #60

SchrodingerZhu opened this issue Dec 9, 2019 · 0 comments

Comments

@SchrodingerZhu
Copy link

SchrodingerZhu commented Dec 9, 2019

when handling strings, the library makes quite a lot extra copy constructions. Some basic improvements:

  • when passing string by value in constructors, please use std::move before assign it to the class field.
  • please notice that for (std::string i : container) will copy-construct a string in each iteration. There are many cases in the library (for example, see system/exception.h) that using a const reference is enough. As the library is to be shown to students, I guess better practice is needed to apply here.
  • string_view can be used if you just want to access some slices (C++17).
@SchrodingerZhu SchrodingerZhu changed the title Try avoid necessary copy constructions Try avoiding unnecessary copy constructions Dec 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant