Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-10-22 12:15:51 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-10-22 12:15:51 +0400
commitddc2dbc2a47ed2439a62e82ad6fba7d8c9dcae28 (patch)
treea7ca593a96652e6f0a784b5c6e37ab2c35b07159 /source/blender/blenlib/intern/BLI_heap.c
parent30fd258a0b407419a369fbb2818c49df6b70968e (diff)
style cleanup
Diffstat (limited to 'source/blender/blenlib/intern/BLI_heap.c')
-rw-r--r--source/blender/blenlib/intern/BLI_heap.c8
1 files changed, 5 insertions, 3 deletions
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--;