Bug 1247615 - Fix off-by-one error in PrefixSet Delta storage compaction. r=froydnj
authorGian-Carlo Pascutto <gcp@mozilla.com>
Fri, 12 Feb 2016 17:09:58 +0100
changeset 284161 de6e8bf0990f99e0dfbe72a1b976c08fba068884
parent 284160 4f450052b2f31e3a2ef171255a141c8e8ec8c65b
child 284162 eece4a58a60cb0b5a491a17e1b84806639621677
push id29998
push userphilringnalda@gmail.com
push dateSun, 14 Feb 2016 03:19:08 +0000
treeherdermozilla-central@e355cacefc88 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1247615
milestone47.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 1247615 - Fix off-by-one error in PrefixSet Delta storage compaction. r=froydnj
toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
--- a/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
@@ -107,35 +107,39 @@ nsUrlClassifierPrefixSet::MakePrefixSet(
   mIndexDeltas.Clear();
   mTotalPrefixes = aLength;
 
   mIndexPrefixes.AppendElement(aPrefixes[0]);
   mIndexDeltas.AppendElement();
 
   uint32_t numOfDeltas = 0;
   uint32_t totalDeltas = 0;
-  uint32_t currentItem = aPrefixes[0];
+  uint32_t previousItem = aPrefixes[0];
   for (uint32_t i = 1; i < aLength; i++) {
     if ((numOfDeltas >= DELTAS_LIMIT) ||
-          (aPrefixes[i] - currentItem >= MAX_INDEX_DIFF)) {
+          (aPrefixes[i] - previousItem >= MAX_INDEX_DIFF)) {
+      // Compact the previous element.
+      // Note there is always at least one element when we get here,
+      // because we created the first element before the loop.
+      mIndexDeltas.LastElement().Compact();
       mIndexDeltas.AppendElement();
-      mIndexDeltas[mIndexDeltas.Length() - 1].Compact();
       mIndexPrefixes.AppendElement(aPrefixes[i]);
       numOfDeltas = 0;
     } else {
-      uint16_t delta = aPrefixes[i] - currentItem;
-      mIndexDeltas[mIndexDeltas.Length() - 1].AppendElement(delta);
+      uint16_t delta = aPrefixes[i] - previousItem;
+      mIndexDeltas.LastElement().AppendElement(delta);
       numOfDeltas++;
       totalDeltas++;
     }
-    currentItem = aPrefixes[i];
+    previousItem = aPrefixes[i];
   }
 
+  mIndexDeltas.LastElement().Compact();
+  mIndexDeltas.Compact();
   mIndexPrefixes.Compact();
-  mIndexDeltas.Compact();
 
   LOG(("Total number of indices: %d", aLength));
   LOG(("Total number of deltas: %d", totalDeltas));
   LOG(("Total number of delta chunks: %d", mIndexDeltas.Length()));
 
   return NS_OK;
 }