From c212503437045669997f3d8b9f109b74758da412 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 3 Aug 2013 22:04:47 +0000 Subject: minor changes to BLI_heap, save some CPU cycles. added an assert for incorrect use of BLI_heap_remove --- source/blender/blenlib/intern/BLI_heap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source/blender/blenlib/intern/BLI_heap.c') 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); -- cgit v1.2.3