RESOLVED FIXED149397
Use modern for-loops in WebCore/loader.
https://bugs.webkit.org/show_bug.cgi?id=149397
Summary Use modern for-loops in WebCore/loader.
Hunseop Jeong
Reported 2015-09-21 01:00:11 PDT
Refactor the for-loops using the ranged-for loops and auto keyword.
Attachments
Patch (45.57 KB, patch)
2015-09-21 01:17 PDT, Hunseop Jeong
no flags
Patch (46.16 KB, patch)
2015-09-21 01:25 PDT, Hunseop Jeong
no flags
Archive of layout-test-results from ews103 for mac-mavericks (617.89 KB, application/zip)
2015-09-21 01:59 PDT, Build Bot
no flags
Archive of layout-test-results from ews107 for mac-mavericks-wk2 (678.64 KB, application/zip)
2015-09-21 02:23 PDT, Build Bot
no flags
Patch (44.73 KB, patch)
2015-09-21 18:16 PDT, Hunseop Jeong
no flags
Patch (45.30 KB, patch)
2015-09-23 02:17 PDT, Hunseop Jeong
no flags
PatchWithoutCopying (45.26 KB, patch)
2015-09-23 05:53 PDT, Hunseop Jeong
no flags
Patch (45.28 KB, patch)
2015-09-29 21:20 PDT, Hunseop Jeong
no flags
Hunseop Jeong
Comment 1 2015-09-21 01:17:46 PDT
WebKit Commit Bot
Comment 2 2015-09-21 01:20:50 PDT
Attachment 261638 [details] did not pass style-queue: ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:193: Multi line control clauses should use braces. [whitespace/braces] [4] ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:777: Multi line control clauses should use braces. [whitespace/braces] [4] ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:815: Multi line control clauses should use braces. [whitespace/braces] [4] ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:816: Multi line control clauses should use braces. [whitespace/braces] [4] ERROR: Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp:250: Multi line control clauses should use braces. [whitespace/braces] [4] Total errors found: 5 in 19 files If any of these errors are false positives, please file a bug against check-webkit-style.
Hunseop Jeong
Comment 3 2015-09-21 01:25:02 PDT
WebKit Commit Bot
Comment 4 2015-09-21 01:28:00 PDT
Attachment 261639 [details] did not pass style-queue: ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:193: Multi line control clauses should use braces. [whitespace/braces] [4] ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:777: Multi line control clauses should use braces. [whitespace/braces] [4] ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:815: Multi line control clauses should use braces. [whitespace/braces] [4] ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:816: Multi line control clauses should use braces. [whitespace/braces] [4] ERROR: Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp:250: Multi line control clauses should use braces. [whitespace/braces] [4] Total errors found: 5 in 19 files If any of these errors are false positives, please file a bug against check-webkit-style.
Build Bot
Comment 5 2015-09-21 01:59:49 PDT
Comment on attachment 261639 [details] Patch Attachment 261639 [details] did not pass mac-ews (mac): Output: http://webkit-queues.webkit.org/results/192555 New failing tests: fast/events/before-unload-remove-and-add-subframe.html fast/events/before-unload-adopt-subframe-to-outside.html
Build Bot
Comment 6 2015-09-21 01:59:52 PDT
Created attachment 261642 [details] Archive of layout-test-results from ews103 for mac-mavericks The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews103 Port: mac-mavericks Platform: Mac OS X 10.9.5
Build Bot
Comment 7 2015-09-21 02:23:28 PDT
Comment on attachment 261639 [details] Patch Attachment 261639 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.webkit.org/results/192591 New failing tests: fast/events/before-unload-remove-and-add-subframe.html fast/events/before-unload-adopt-subframe-to-outside.html
Build Bot
Comment 8 2015-09-21 02:23:31 PDT
Created attachment 261643 [details] Archive of layout-test-results from ews107 for mac-mavericks-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews107 Port: mac-mavericks-wk2 Platform: Mac OS X 10.9.5
Hunseop Jeong
Comment 9 2015-09-21 18:16:40 PDT
WebKit Commit Bot
Comment 10 2015-09-21 18:33:22 PDT
Attachment 261711 [details] did not pass style-queue: ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:193: Multi line control clauses should use braces. [whitespace/braces] [4] ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:777: Multi line control clauses should use braces. [whitespace/braces] [4] ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:815: Multi line control clauses should use braces. [whitespace/braces] [4] ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:816: Multi line control clauses should use braces. [whitespace/braces] [4] ERROR: Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp:250: Multi line control clauses should use braces. [whitespace/braces] [4] Total errors found: 5 in 19 files If any of these errors are false positives, please file a bug against check-webkit-style.
Hunseop Jeong
Comment 11 2015-09-21 19:19:04 PDT
(In reply to comment #10) > Attachment 261711 [details] did not pass style-queue: > > > ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:193: Multi line control > clauses should use braces. [whitespace/braces] [4] > ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:777: Multi line control > clauses should use braces. [whitespace/braces] [4] > ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:815: Multi line control > clauses should use braces. [whitespace/braces] [4] > ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:816: Multi line control > clauses should use braces. [whitespace/braces] [4] > ERROR: Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp:250: Multi > line control clauses should use braces. [whitespace/braces] [4] > Total errors found: 5 in 19 files > > > If any of these errors are false positives, please file a bug against > check-webkit-style. It looks false alarm. These modified codes don't need the braces.
Chris Dumez
Comment 12 2015-09-21 19:27:10 PDT
(In reply to comment #11) > (In reply to comment #10) > > Attachment 261711 [details] did not pass style-queue: > > > > > > ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:193: Multi line control > > clauses should use braces. [whitespace/braces] [4] > > ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:777: Multi line control > > clauses should use braces. [whitespace/braces] [4] > > ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:815: Multi line control > > clauses should use braces. [whitespace/braces] [4] > > ERROR: Source/WebCore/loader/icon/IconDatabase.cpp:816: Multi line control > > clauses should use braces. [whitespace/braces] [4] > > ERROR: Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp:250: Multi > > line control clauses should use braces. [whitespace/braces] [4] > > Total errors found: 5 in 19 files > > > > > > If any of these errors are false positives, please file a bug against > > check-webkit-style. > > > It looks false alarm. These modified codes don't need the braces. I don't think they are. This usually means you have extra spaces on the next line. You should remove those extra spaces.
Chris Dumez
Comment 13 2015-09-21 19:28:20 PDT
Comment on attachment 261711 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=261711&action=review > Source/WebCore/loader/icon/IconDatabase.cpp:195 > For example, you probably have white spaces on this line.
Darin Adler
Comment 14 2015-09-21 19:30:24 PDT
Comment on attachment 261711 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=261711&action=review > Source/WebCore/loader/DocumentLoader.cpp:1146 > + RefPtr<ResourceLoader> loader = entry.key; No need for the reference count churn here. Could just be: auto& loader = entry.key; > Source/WebCore/loader/FrameLoader.cpp:1860 > + for (auto& response : m_documentLoader->responses()) { I think that in both the old and new code this is risky. What if sendRemainingDelegateMessages calls something that ends up calling back through to us and deletes the object currently in m_documentLoader or adds responses to the vector? We probably need to make a copy of the response vector and iterate that. Not sure how to test this. > Source/WebCore/loader/appcache/ApplicationCache.cpp:156 > + for (auto& whiteURL : m_onlineWhitelist) { I think whitelistURL would be better than whiteURL. > Source/WebCore/loader/appcache/ApplicationCacheGroup.cpp:734 > + for (auto& loader : m_pendingMasterResourceLoaders) > + associateDocumentLoaderWithCache(loader, m_cacheBeingUpdated.get()); > + Why the new extra blank line here? Please don’t include that. > Source/WebCore/loader/appcache/ApplicationCacheHost.cpp:308 > + for (auto& deferred : m_deferredEvents) I think I’d call this “event” rather than “deferred”. > Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp:753 > + for (auto& url : onlineWhitelist) { I think whitelistURL is probably the best name for this, better than just url. > Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp:138 > + RetainPtr<CFDictionaryRef> subresource = createPropertyListRepresentation(resource.get(), Subresource); > if (subresource) I’d suggest putting the RetainPtr inside the if. > Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp:149 > + RetainPtr<CFDictionaryRef> subframeArchive = createPropertyListRepresentation(subframe.get()); > if (subframeArchive) I’d suggest putting the RetainPtr inside the if. > Source/WebCore/loader/cache/CachedResourceLoader.cpp:1093 > + for (auto& res : m_preloads) { Would be nice to rename this resource instead of "res". > Source/WebCore/loader/icon/IconDatabase.cpp:817 > + for (auto& loader : m_loadersPendingDecision) > + if (loader->refCount() > 1) > + loader->iconLoadDecisionAvailable(); Should have braces for WebKit coding style.
Hunseop Jeong
Comment 15 2015-09-21 23:51:46 PDT
(In reply to comment #13) > Comment on attachment 261711 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=261711&action=review > > > Source/WebCore/loader/icon/IconDatabase.cpp:195 > > > > For example, you probably have white spaces on this line. Oops,, I didn't see the white spaces.. I will remove the white spaces.
Hunseop Jeong
Comment 16 2015-09-21 23:57:35 PDT
Comment on attachment 261711 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=261711&action=review >> Source/WebCore/loader/FrameLoader.cpp:1860 >> + for (auto& response : m_documentLoader->responses()) { > > I think that in both the old and new code this is risky. What if sendRemainingDelegateMessages calls something that ends up calling back through to us and deletes the object currently in m_documentLoader or adds responses to the vector? We probably need to make a copy of the response vector and iterate that. Not sure how to test this. You mean, We need to make a copy of the response vector to escape the risk. Like as : Vector<ResourceResponse> responses; responses.reserveCapacity(m_documentLoader->responses().size()); for (auto& response : m_documentLoader->responses()) responses.append(response); for (auto& response : responses) { ... >> Source/WebCore/loader/appcache/ApplicationCache.cpp:156 >> + for (auto& whiteURL : m_onlineWhitelist) { > > I think whitelistURL would be better than whiteURL. Okay, Naming is very hard work.
Darin Adler
Comment 17 2015-09-22 08:52:53 PDT
Comment on attachment 261711 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=261711&action=review >>> Source/WebCore/loader/FrameLoader.cpp:1860 >>> + for (auto& response : m_documentLoader->responses()) { >> >> I think that in both the old and new code this is risky. What if sendRemainingDelegateMessages calls something that ends up calling back through to us and deletes the object currently in m_documentLoader or adds responses to the vector? We probably need to make a copy of the response vector and iterate that. Not sure how to test this. > > You mean, We need to make a copy of the response vector to escape the risk. > Like as : > > Vector<ResourceResponse> responses; > responses.reserveCapacity(m_documentLoader->responses().size()); > for (auto& response : m_documentLoader->responses()) > responses.append(response); > > for (auto& response : responses) { > ... Yes, copying the response vector is one thing that might help. It also might have a performance cost or create other problems, so I think we need to look into testing this, not just writing code that looks right. If we do want to copy it, it’s actually much easier to copy than the code above. It’s this one-liner: auto responsesCopy = m_documentLoader->responses(); No need for a loop with reserveCapacity and append. (And if we did write the loop, it should be with reserveInitialCapacity and uncheckedAppend instead.)
Hunseop Jeong
Comment 18 2015-09-23 02:17:46 PDT
Hunseop Jeong
Comment 19 2015-09-23 05:53:05 PDT
Created attachment 261821 [details] PatchWithoutCopying
Hunseop Jeong
Comment 20 2015-09-23 05:59:07 PDT
(In reply to comment #17) > Comment on attachment 261711 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=261711&action=review > > >>> Source/WebCore/loader/FrameLoader.cpp:1860 > >>> + for (auto& response : m_documentLoader->responses()) { > >> > >> I think that in both the old and new code this is risky. What if sendRemainingDelegateMessages calls something that ends up calling back through to us and deletes the object currently in m_documentLoader or adds responses to the vector? We probably need to make a copy of the response vector and iterate that. Not sure how to test this. > > > > You mean, We need to make a copy of the response vector to escape the risk. > > Like as : > > > > Vector<ResourceResponse> responses; > > responses.reserveCapacity(m_documentLoader->responses().size()); > > for (auto& response : m_documentLoader->responses()) > > responses.append(response); > > > > for (auto& response : responses) { > > ... > > Yes, copying the response vector is one thing that might help. It also might > have a performance cost or create other problems, so I think we need to look > into testing this, not just writing code that looks right. > > If we do want to copy it, it’s actually much easier to copy than the code > above. It’s this one-liner: > > auto responsesCopy = m_documentLoader->responses(); > > No need for a loop with reserveCapacity and append. (And if we did write the > loop, it should be with reserveInitialCapacity and uncheckedAppend instead.) Other comments are done. How to look into testing this? Is it covered by existing layoutTest or PerformanceTest? If we need the deep testing, could you upload this patch without the copying code?
Darin Adler
Comment 21 2015-09-23 08:16:34 PDT
(In reply to comment #20) > How to look into testing this? That’s an excellent question. I don’t know exactly how to test it, other than the suggestions I made above about sendRemainingDelegateMessages. We somehow have to make a test case where those delegate messages trigger a change in the frame loader, probably by loading a new page in the frame, but with a load that is as synchronous as possible (perhaps loading about:blank). > Is it covered by existing layoutTest or PerformanceTest? Definitely not, because if there is a bug here, it already existed in the old code. > If we need the deep testing, could you upload this patch without the copying > code? Sure, we can do refactoring without fixing this, but someone should really be following up to explore whether this is a bug.
Hunseop Jeong
Comment 22 2015-09-23 18:58:30 PDT
(In reply to comment #21) > (In reply to comment #20) > > How to look into testing this? > > That’s an excellent question. I don’t know exactly how to test it, other > than the suggestions I made above about sendRemainingDelegateMessages. We > somehow have to make a test case where those delegate messages trigger a > change in the frame loader, probably by loading a new page in the frame, but > with a load that is as synchronous as possible (perhaps loading about:blank). > > > Is it covered by existing layoutTest or PerformanceTest? > > Definitely not, because if there is a bug here, it already existed in the > old code. > > > If we need the deep testing, could you upload this patch without the copying > > code? > > Sure, we can do refactoring without fixing this, but someone should really > be following up to explore whether this is a bug. Thanks. I also try to explore whether this is a bug.
Hunseop Jeong
Comment 23 2015-09-29 21:20:25 PDT
WebKit Commit Bot
Comment 24 2015-09-29 22:54:16 PDT
Comment on attachment 262139 [details] Patch Clearing flags on attachment: 262139 Committed r190338: <http://trac.webkit.org/changeset/190338>
WebKit Commit Bot
Comment 25 2015-09-29 22:54:23 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.