From ddc2dbc2a47ed2439a62e82ad6fba7d8c9dcae28 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 22 Oct 2012 08:15:51 +0000 Subject: style cleanup --- source/blender/blenlib/intern/BLI_heap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 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 d3b1bdfa8fa..42dca360f4c 100644 --- a/source/blender/blenlib/intern/BLI_heap.c +++ b/source/blender/blenlib/intern/BLI_heap.c @@ -122,6 +122,7 @@ static void heap_up(Heap *heap, unsigned int i) Heap *BLI_heap_new_ex(unsigned int tot_reserve) { Heap *heap = (Heap *)MEM_callocN(sizeof(Heap), __func__); + /* ensure we have at least one so we can keep doubling it */ heap->bufsize = MAX2(1, tot_reserve); heap->tree = (HeapNode **)MEM_mallocN(heap->bufsize * sizeof(HeapNode *), "BLIHeapTree"); heap->arena = BLI_memarena_new(1 << 16, "heap arena"); @@ -151,8 +152,8 @@ HeapNode *BLI_heap_insert(Heap *heap, float value, void *ptr) { HeapNode *node; - if ((heap->size + 1) > heap->bufsize) { - heap->bufsize = heap->bufsize * 2; + if (UNLIKELY((heap->size + 1) > heap->bufsize)) { + heap->bufsize *= 2; heap->tree = MEM_reallocN(heap->tree, heap->bufsize * sizeof(*heap->tree)); } @@ -199,8 +200,9 @@ void *BLI_heap_popmin(Heap *heap) heap->tree[0]->ptr = heap->freenodes; heap->freenodes = heap->tree[0]; - if (heap->size == 1) + if (UNLIKELY(heap->size == 1)) { heap->size--; + } else { heap_swap(heap, 0, heap->size - 1); heap->size--; -- cgit v1.2.3