Bug 1562436 - Adjust first pref returned if it is to be skipped. r=njn
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 01 Jul 2019 23:49:41 +0000
changeset 543690 3e4b29e2d1d6c97d819d560480d19d36ea5db50c
parent 543689 53a39e4024511c051187db2a6c501c56c23a77ea
child 543691 d70d3b500a6db99776e3706a93e54aff6137091a
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1562436
milestone69.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 1562436 - Adjust first pref returned if it is to be skipped. r=njn If the first pref entry in the SharedPrefMap array had mIsSkippedByIteration flag set it would have been returned and as such exposed to the user. We don't want that. Differential Revision: https://phabricator.services.mozilla.com/D36453
modules/libpref/SharedPrefMap.h
--- a/modules/libpref/SharedPrefMap.h
+++ b/modules/libpref/SharedPrefMap.h
@@ -475,20 +475,28 @@ class SharedPrefMap {
   // that aIndex is no more than 1 past the last element in the array, since it
   // also takes into account the ranged iteration use case.
   Pref UncheckedGetValueAt(uint32_t aIndex) const {
     return {this, (Entries() + aIndex).get()};
   }
 
  public:
   // C++ range iterator protocol. begin() and end() return references to the
-  // first and last entries in the array. The begin wrapper can be incremented
-  // until it matches the last element in the array, at which point it becomes
-  // invalid and the iteration is over.
-  Pref begin() const { return UncheckedGetValueAt(0); }
+  // first (non-skippable) and last entries in the array. The begin wrapper
+  // can be incremented until it matches the last element in the array, at which
+  // point it becomes invalid and the iteration is over.
+  Pref begin() const {
+    for (uint32_t aIndex = 0; aIndex < Count(); aIndex++) {
+      Pref pref = UncheckedGetValueAt(aIndex);
+      if (!pref.IsSkippedByIteration()) {
+        return pref;
+      }
+    }
+    return end();
+  }
   Pref end() const { return UncheckedGetValueAt(Count()); }
 
   // A cosmetic helper for range iteration. Returns a reference value from a
   // pointer to this instance so that its .begin() and .end() methods can be
   // accessed in a ranged for loop. `map->Iter()` is equivalent to `*map`, but
   // makes its purpose slightly clearer.
   const SharedPrefMap& Iter() const { return *this; }