diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-08-04 02:04:47 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-08-04 02:04:47 +0400 |
commit | c212503437045669997f3d8b9f109b74758da412 (patch) | |
tree | 8ae978d37cd7d27dc7a2ca4f2a16e2d54dfd5468 /source/blender/blenlib/intern/BLI_heap.c | |
parent | 8052bf0ec23e6e49300b461cad8bdbc2474852ab (diff) |
minor changes to BLI_heap, save some CPU cycles.
added an assert for incorrect use of BLI_heap_remove
Diffstat (limited to 'source/blender/blenlib/intern/BLI_heap.c')
-rw-r--r-- | source/blender/blenlib/intern/BLI_heap.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c index c645db4c15e..0aaa3e13b3f 100644 --- a/source/blender/blenlib/intern/BLI_heap.c +++ b/source/blender/blenlib/intern/BLI_heap.c @@ -163,7 +163,7 @@ HeapNode *BLI_heap_insert(Heap *heap, float value, void *ptr) { HeapNode *node; - if (UNLIKELY((heap->size + 1) > heap->bufsize)) { + if (UNLIKELY(heap->size >= heap->bufsize)) { heap->bufsize *= 2; heap->tree = MEM_reallocN(heap->tree, heap->bufsize * sizeof(*heap->tree)); } @@ -184,7 +184,7 @@ HeapNode *BLI_heap_insert(Heap *heap, float value, void *ptr) heap->size++; - heap_up(heap, heap->size - 1); + heap_up(heap, node->index); return node; } @@ -230,6 +230,8 @@ void BLI_heap_remove(Heap *heap, HeapNode *node) { unsigned int i = node->index; + BLI_assert(heap->size != 0); + while (i > 0) { unsigned int p = HEAP_PARENT(i); |