RESOLVED FIXED 128644
Remove some unintended copies in ranged for loops
https://bugs.webkit.org/show_bug.cgi?id=128644
Summary Remove some unintended copies in ranged for loops
Brent Fulgham
Reported 2014-02-11 19:11:57 PST
Once I noticed the handful of errors in Bug 128578, I did some more searching and turned up a few more. Per http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2049.pdf, the ranged iterator syntax: for( type-specifier-seq simple-declarator : expression ) statement is syntactically equivalent to typedef decltype(expression) C; auto&& rng(expression); for (auto begin(std::For<C>::begin(rng)), end(std::For<C>::end(rng)); begin != end; ++ begin) { type-specifier-seq simple-declarator(∗begin); statement } The issue here is that the type of auto (instead of 'auto&' or 'const auto&') causes us to make a copy of each element as we pass through the loop. When the container is just a set of pointers, it's not much of an issue. But when we have iterate over reference-counted types, strings, or other larger objects we incur unnecessary costs.
Attachments
Patch (15.09 KB, patch)
2014-02-11 19:54 PST, Brent Fulgham
andersca: review+
Brent Fulgham
Comment 1 2014-02-11 19:54:49 PST
Brent Fulgham
Comment 2 2014-02-12 09:05:23 PST
Note You need to log in before you can comment on or make changes to this bug.