Permalink
Browse files

list: fix sorted insert

  • Loading branch information...
indutny committed Nov 17, 2012
1 parent 58412e5 commit cc2285d2289890648f732d0438885c18735ac1dd
Showing with 4 additions and 3 deletions.
  1. +1 −1 src/lir.cc
  2. +3 −2 src/list.h
View
@@ -931,7 +931,7 @@ LInterval* LGen::Split(LInterval* i, int pos) {
LUse* use = i->uses()->At(j);
// Uses are sorted - so break early
- if (use->instr()->id < pos) continue;
+ if (use->instr()->id < pos) break;
i->uses()->RemoveAt(j);
child->uses()->Unshift(use);
View
@@ -92,7 +92,7 @@ class SortableList {
// Perform binary search for correct position
int middle_pos;
int cmp;
- for (int i = 0, j = length() - 1; i < j; ) {
+ for (int i = 0, j = length() - 1; i <= j; ) {
middle_pos = (i + j) >> 1;
T* middle = map_[middle_pos];
@@ -114,8 +114,9 @@ class SortableList {
}
len_++;
+ assert(insert_pos >= 0 && insert_pos < len_);
+
for (int i = len_ - 1; i > insert_pos; i--) {
- assert(map_[i - 1] != NULL);
map_[i] = map_[i - 1];
}
map_[insert_pos] = value;

0 comments on commit cc2285d

Please sign in to comment.