You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
The text was updated successfully, but these errors were encountered:
SchrodingerZhu
changed the title
Try avoid necessary copy constructions
Try avoiding unnecessary copy constructions
Dec 9, 2019
when handling strings, the library makes quite a lot extra copy constructions. Some basic improvements:
std::move
before assign it to the class field.for (std::string i : container)
will copy-construct a string in each iteration. There are many cases in the library (for example, seesystem/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).The text was updated successfully, but these errors were encountered: