Bug 1317241 - Converts for(...; ...; ...) loops to use the new range-based loops in C++11 in dom/. r=baku
authorAndi-Bogdan Postelnicu <bpostelnicu@mozilla.com>
Mon, 14 Nov 2016 11:31:11 +0200
changeset 367574 494c49290b534767cd0c15d98e981ea7de5caab8
parent 367573 21589b5736232ee817589aeb3cc1bcc08720e766
child 367575 5b3a57978bd4270560d334dc08dec509643b4984
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1317241
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1317241 - Converts for(...; ...; ...) loops to use the new range-based loops in C++11 in dom/. r=baku MozReview-Commit-ID: ysMKgcL3YQ
dom/asmjscache/AsmJSCache.cpp
dom/base/DOMIntersectionObserver.cpp
dom/base/nsContentUtils.cpp
dom/indexedDB/ActorsParent.cpp
--- a/dom/asmjscache/AsmJSCache.cpp
+++ b/dom/asmjscache/AsmJSCache.cpp
@@ -1099,20 +1099,19 @@ FindHashMatch(const Metadata& aMetadata,
   // asm.js modules where the first sNumFastHashChars are the same. The
   // mFullHash of each cache entry can have a different mNumChars so the fast
   // hash allows us to avoid performing up to Metadata::kNumEntries separate
   // full hashes.
   uint32_t numChars = aReadParams.mLimit - aReadParams.mBegin;
   MOZ_ASSERT(numChars > sNumFastHashChars);
   uint32_t fastHash = HashString(aReadParams.mBegin, sNumFastHashChars);
 
-  for (unsigned i = 0; i < Metadata::kNumEntries ; i++) {
+  for (auto entry : aMetadata.mEntries) {
     // Compare the "fast hash" first to see whether it is worthwhile to
     // hash all the chars.
-    Metadata::Entry entry = aMetadata.mEntries[i];
     if (entry.mFastHash != fastHash) {
       continue;
     }
 
     // Assuming we have enough characters, hash all the chars it would take
     // to match this cache entry and compare to the cache entry. If we get a
     // hit we'll still do a full source match later (in the JS engine), but
     // the full hash match means this is probably the cache entry we want.
@@ -1842,47 +1841,44 @@ CreateClient()
 namespace IPC {
 
 using mozilla::dom::asmjscache::Metadata;
 using mozilla::dom::asmjscache::WriteParams;
 
 void
 ParamTraits<Metadata>::Write(Message* aMsg, const paramType& aParam)
 {
-  for (unsigned i = 0; i < Metadata::kNumEntries; i++) {
-    const Metadata::Entry& entry = aParam.mEntries[i];
+  for (auto entry : aParam.mEntries) {
     WriteParam(aMsg, entry.mFastHash);
     WriteParam(aMsg, entry.mNumChars);
     WriteParam(aMsg, entry.mFullHash);
     WriteParam(aMsg, entry.mModuleIndex);
   }
 }
 
 bool
 ParamTraits<Metadata>::Read(const Message* aMsg, PickleIterator* aIter,
                             paramType* aResult)
 {
-  for (unsigned i = 0; i < Metadata::kNumEntries; i++) {
-    Metadata::Entry& entry = aResult->mEntries[i];
+  for (auto& entry : aResult->mEntries) {
     if (!ReadParam(aMsg, aIter, &entry.mFastHash) ||
         !ReadParam(aMsg, aIter, &entry.mNumChars) ||
         !ReadParam(aMsg, aIter, &entry.mFullHash) ||
         !ReadParam(aMsg, aIter, &entry.mModuleIndex))
     {
       return false;
     }
   }
   return true;
 }
 
 void
 ParamTraits<Metadata>::Log(const paramType& aParam, std::wstring* aLog)
 {
-  for (unsigned i = 0; i < Metadata::kNumEntries; i++) {
-    const Metadata::Entry& entry = aParam.mEntries[i];
+  for (auto entry : aParam.mEntries) {
     LogParam(entry.mFastHash, aLog);
     LogParam(entry.mNumChars, aLog);
     LogParam(entry.mFullHash, aLog);
     LogParam(entry.mModuleIndex, aLog);
   }
 }
 
 void
--- a/dom/base/DOMIntersectionObserver.cpp
+++ b/dom/base/DOMIntersectionObserver.cpp
@@ -118,18 +118,18 @@ DOMIntersectionObserver::SetRootMargin(c
   nsCSSParser parser(nullptr);
   nsCSSValue value;
   if (!parser.ParseMarginString(aString, nullptr, 0, value, true)) {
     return false;
   }
 
   mRootMargin = value.GetRectValue();
 
-  for (uint32_t i = 0; i < ArrayLength(nsCSSRect::sides); ++i) {
-    nsCSSValue value = mRootMargin.*nsCSSRect::sides[i];
+  for (auto side : nsCSSRect::sides) {
+    nsCSSValue& value = mRootMargin.*side;
     if (!(value.IsPixelLengthUnit() || value.IsPercentLengthUnit())) {
       return false;
     }
   }
 
   return true;
 }
 
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -7120,18 +7120,18 @@ bool
 nsContentUtils::IsForbiddenSystemRequestHeader(const nsACString& aHeader)
 {
   static const char *kInvalidHeaders[] = {
     "accept-charset", "accept-encoding", "access-control-request-headers",
     "access-control-request-method", "connection", "content-length",
     "cookie", "cookie2", "date", "dnt", "expect", "host", "keep-alive",
     "origin", "referer", "te", "trailer", "transfer-encoding", "upgrade", "via"
   };
-  for (uint32_t i = 0; i < ArrayLength(kInvalidHeaders); ++i) {
-    if (aHeader.LowerCaseEqualsASCII(kInvalidHeaders[i])) {
+  for (auto& kInvalidHeader : kInvalidHeaders) {
+    if (aHeader.LowerCaseEqualsASCII(kInvalidHeader)) {
       return true;
     }
   }
   return false;
 }
 
 // static
 bool
@@ -9141,25 +9141,25 @@ ShouldEscape(nsIContent* aParent)
     // browsing context. However the latter seems to be a spec bug
     // and Gecko hasn't traditionally done the former.
     nsGkAtoms::noscript
   };
   static mozilla::BloomFilter<12, nsIAtom> sFilter;
   static bool sInitialized = false;
   if (!sInitialized) {
     sInitialized = true;
-    for (uint32_t i = 0; i < ArrayLength(nonEscapingElements); ++i) {
-      sFilter.add(nonEscapingElements[i]);
+    for (auto& nonEscapingElement : nonEscapingElements) {
+      sFilter.add(nonEscapingElement);
     }
   }
 
   nsIAtom* tag = aParent->NodeInfo()->NameAtom();
   if (sFilter.mightContain(tag)) {
-    for (uint32_t i = 0; i < ArrayLength(nonEscapingElements); ++i) {
-      if (tag == nonEscapingElements[i]) {
+    for (auto& nonEscapingElement : nonEscapingElements) {
+      if (tag == nonEscapingElement) {
         return false;
       }
     }
   }
   return true;
 }
 
 static inline bool
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -26151,19 +26151,19 @@ ObjectStoreAddOrPutRequestOp::DoDatabase
       char keyPropBuffer[keyPropSize];
       LittleEndian::writeUint64(keyPropBuffer, keyPropValue);
 
       auto iter = cloneData.Iter();
       DebugOnly<bool> result =
        iter.AdvanceAcrossSegments(cloneData, cloneInfo.offsetToKeyProp());
       MOZ_ASSERT(result);
 
-      for (uint32_t index = 0; index < keyPropSize; index++) {
+      for (char index : keyPropBuffer) {
         char* keyPropPointer = iter.Data();
-        *keyPropPointer = keyPropBuffer[index];
+        *keyPropPointer = index;
 
         result = iter.AdvanceAcrossSegments(cloneData, 1);
         MOZ_ASSERT(result);
       }
     }
   }
 
   key.BindToStatement(stmt, NS_LITERAL_CSTRING("key"));