Bug 998507 - add some assertions to BinarySearch (r=me)
authorLuke Wagner <luke@mozilla.com>
Tue, 22 Apr 2014 13:53:37 -0500
changeset 179960 139c2e8c264ff015779ca62b87b81f41396542be
parent 179959 098f943ba58dcddc8e469f8ecf430998d1ef1d69
child 179961 418c50532eea49db1b765db1db23bac93403ac08
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersme
bugs998507
milestone31.0a1
Bug 998507 - add some assertions to BinarySearch (r=me)
mfbt/BinarySearch.h
--- a/mfbt/BinarySearch.h
+++ b/mfbt/BinarySearch.h
@@ -37,16 +37,20 @@ BinarySearch(const Container &c, size_t 
   MOZ_ASSERT(begin <= end);
 
   size_t low = begin;
   size_t high = end;
   while (low != high) {
     size_t middle = low + (high - low) / 2;
     const T &middleValue = c[middle];
 
+    MOZ_ASSERT(c[low] <= c[middle]);
+    MOZ_ASSERT(c[middle] <= c[high - 1]);
+    MOZ_ASSERT(c[low] <= c[high - 1]);
+
     if (target == middleValue) {
       *matchOrInsertionPoint = middle;
       return true;
     }
 
     if (target < middleValue)
       high = middle;
     else