Bug 128578

Summary: Correct some uses of 'auto'
Product: WebKit Reporter: Brent Fulgham <bfulgham>
Component: WebCore Misc.Assignee: Brent Fulgham <bfulgham>
Status: RESOLVED FIXED    
Severity: Normal CC: aboxhall, andersca, apinheiro, bfulgham, cfleizach, cmarcelo, commit-queue, darin, dmazzoni, esprehn+autocc, glenn, gyuyoung.kim, jamesr, jdiggs, jfernandez, kangil.han, kondapallykalyan, luiz, macpherson, mario, menard, rego, samuel_white, svillar, tonikitoo
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch none

Description Brent Fulgham 2014-02-10 21:19:27 PST
I recently noticed a number of places where we were using the following idiom:

for (auto rect : dirtyRects) {
    // ... do some stuff ...
}

The C++11 standard indicates that this produces something along the lines of:

"auto elem = *__begin;" which copies each element.

We should prefer to use "for (const auto& ..." wherever possible, or "for (auto&" in cases where we need to modify the elements.
Comment 1 Brent Fulgham 2014-02-10 22:16:47 PST
Created attachment 223809 [details]
Patch
Comment 2 WebKit Commit Bot 2014-02-11 09:31:06 PST
Comment on attachment 223809 [details]
Patch

Clearing flags on attachment: 223809

Committed r163882: <http://trac.webkit.org/changeset/163882>
Comment 3 WebKit Commit Bot 2014-02-11 09:31:10 PST
All reviewed patches have been landed.  Closing bug.
Comment 4 Darin Adler 2014-02-11 12:12:33 PST
I wholeheartedly agree that auto is not good when this churn happens. And I’m really glad you fixed this!

I don’t really prefer const auto& over auto&, though. I can’t think of any harm that comes from using auto&. If we only have const access to the collection, then the const works automatically. If we have non-const access, then it doesn’t seem worth the extra word just to narrow the access for the body of the loop.