Bug 998507 - add some assertions to BinarySearch (r=me)
authorLuke Wagner <luke@mozilla.com>
Tue, 22 Apr 2014 13:53:37 -0500
changeset 179554 139c2e8c264ff015779ca62b87b81f41396542be
parent 179553 098f943ba58dcddc8e469f8ecf430998d1ef1d69
child 179555 418c50532eea49db1b765db1db23bac93403ac08
push id42562
push userlwagner@mozilla.com
push dateTue, 22 Apr 2014 18:55:50 +0000
treeherdermozilla-inbound@139c2e8c264f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs998507
milestone31.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 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