NEW 127506
Avoid unnecessary copies in range-based for-loops
https://bugs.webkit.org/show_bug.cgi?id=127506
Summary Avoid unnecessary copies in range-based for-loops
Zan Dobersek
Reported 2014-01-23 12:46:49 PST
In around 20 files range-based for-loops are used that assign each iterated value to an inferred non-reference type, causing copies: for (auto elem : range) { ... } auto& or const auto& should be used instead. Using auto&& in these loops would be the perfect solution, and there are plans to further simplify the range-based for-loops in the future based on using that type. I don't know if using auto&& now would be feasible for the project. http://open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3853.htm
Attachments
Patch (33.25 KB, patch)
2014-01-23 12:53 PST, Zan Dobersek
no flags
Zan Dobersek
Comment 1 2014-01-23 12:53:12 PST
Brent Fulgham
Comment 2 2014-01-30 10:07:26 PST
(In reply to comment #0) > Using auto&& in these loops would be the perfect solution, and there are plans to further simplify the range-based for-loops in the future based on using that type. I don't know if using auto&& now would be feasible for the project. > http://open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3853.htm What would be the problem with using auto&& now? It's valid on all compilers we support, isn't it?
Zan Dobersek
Comment 3 2014-02-17 01:13:35 PST
(In reply to comment #2) > (In reply to comment #0) > > Using auto&& in these loops would be the perfect solution, and there are plans to further simplify the range-based for-loops in the future based on using that type. I don't know if using auto&& now would be feasible for the project. > > http://open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3853.htm > > What would be the problem with using auto&& now? It's valid on all compilers we support, isn't it? It should be (haven't tested out MSVC). I'm concerned whether it would be possible to enforce the use of auto&& through the style guidelines and whether the relative complexity overhead is acceptable until all the supported compilers actually support the simplified syntax.
Zan Dobersek
Comment 4 2014-02-17 01:14:06 PST
Comment on attachment 222019 [details] Patch This patch needs updating.
Alexey Proskuryakov
Comment 5 2014-02-17 10:30:24 PST
> What would be the problem with using auto&& now? It's valid on all compilers we support, isn't it? FWIW, I'm still not sure what the benefit would be. My understanding is that auto&& is superior for library code, where it allows for a wider range of types to work. But in normal WebCore code, isn't it best to use the most specific form that compiles? Less generality makes code more readable. In other words, I'd suggest that we prefer auto& or const auto&, and only use auto&& when that's required for successful compilation.
Note You need to log in before you can comment on or make changes to this bug.