Bug 128578 - Correct some uses of 'auto'
Summary: Correct some uses of 'auto'
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Brent Fulgham
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-10 21:19 PST by Brent Fulgham
Modified: 2014-02-11 12:15 PST (History)
25 users (show)

See Also:


Attachments
Patch (14.73 KB, patch)
2014-02-10 22:16 PST, Brent Fulgham
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.