diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-12-08 10:29:22 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-12-08 10:29:22 +0400 |
commit | c005fb407bbb7aac4cf138fbba903bbb2c821c93 (patch) | |
tree | a49185234ce1a01d26e8f1632e29323025322d17 | |
parent | 8a9a060b673bb9b8c08967ccbd8009ca24cde4d1 (diff) |
Util-defines: avoid multiple calculation/access for MIN/MAX macros
-rw-r--r-- | source/blender/blenkernel/intern/bmfont.c | 3 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_utildefines.h | 17 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_heap.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_mempool.c | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 5 |
5 files changed, 18 insertions, 11 deletions
diff --git a/source/blender/blenkernel/intern/bmfont.c b/source/blender/blenkernel/intern/bmfont.c index e962e8ca831..79b3f89da20 100644 --- a/source/blender/blenkernel/intern/bmfont.c +++ b/source/blender/blenkernel/intern/bmfont.c @@ -68,9 +68,6 @@ void printfGlyph(bmGlyph *glyph) printf(" advan: %3d reser: %3d\n", glyph->advance, glyph->reserved); } -#define MAX2(x, y) ((x) > (y) ? (x) : (y)) -#define MAX3(x, y, z) (MAX2(MAX2((x), (y)), (z))) - void calcAlpha(ImBuf *ibuf) { int i; diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 9e1297658b8..ef2c61cc45a 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -48,11 +48,26 @@ #endif /* min/max */ +#if defined(__GNUC__) || defined(__clang__) + +#define MIN2(x, y) ({ \ + typeof(x) x_ = (x); \ + typeof(y) y_ = (y); \ + ((x_) < (y_) ? (x_) : (y_)); }) + +#define MAX2(x, y) ({ \ + typeof(x) x_ = (x); \ + typeof(y) y_ = (y); \ + ((x_) > (y_) ? (x_) : (y_)); }) + +#else #define MIN2(x, y) ((x) < (y) ? (x) : (y)) +#define MAX2(x, y) ((x) > (y) ? (x) : (y)) +#endif + #define MIN3(x, y, z) (MIN2(MIN2((x), (y)), (z))) #define MIN4(x, y, z, a) (MIN2(MIN2((x), (y)), MIN2((z), (a)))) -#define MAX2(x, y) ((x) > (y) ? (x) : (y)) #define MAX3(x, y, z) (MAX2(MAX2((x), (y)), (z))) #define MAX4(x, y, z, a) (MAX2(MAX2((x), (y)), MAX2((z), (a)))) diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c index 206a8041c4a..55dee4e8677 100644 --- a/source/blender/blenlib/intern/BLI_heap.c +++ b/source/blender/blenlib/intern/BLI_heap.c @@ -125,7 +125,7 @@ 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->bufsize = MAX2(1u, tot_reserve); heap->tree = (HeapNode **)MEM_mallocN(heap->bufsize * sizeof(HeapNode *), "BLIHeapTree"); heap->arena = BLI_memarena_new(MEM_SIZE_OPTIMAL(1 << 16), "heap arena"); diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index 28539d9ca34..c2b54023621 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -257,7 +257,7 @@ BLI_mempool *BLI_mempool_create(unsigned int esize, unsigned int totelem, } if (flag & BLI_MEMPOOL_ALLOW_ITER) { - pool->esize = MAX2(esize, (int)sizeof(BLI_freenode)); + pool->esize = MAX2(esize, (unsigned int)sizeof(BLI_freenode)); } else { pool->esize = esize; diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index fe9e9573957..fe38ce2d86a 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -66,11 +66,6 @@ BlenderDefRNA DefRNA = {NULL, {NULL, NULL}, {NULL, NULL}, NULL, 0, 0, 0, 1, 1}; /* Duplicated code since we can't link in blenkernel or blenlib */ -#ifndef MIN2 -#define MIN2(x, y) ((x) < (y) ? (x) : (y)) -#define MAX2(x, y) ((x) > (y) ? (x) : (y)) -#endif - /* pedantic check for '.', do this since its a hassle for translators */ #ifndef NDEBUG # define DESCR_CHECK(description, id1, id2) \ |