[Bf-blender-cvs] [8ac69ff9dcf] master: Cleanup: use uint type in BLI
Campbell Barton
noreply at git.blender.org
Sat Oct 28 08:44:20 CEST 2017
Commit: 8ac69ff9dcfc6aba8b5de8d53658612c8411b43b
Author: Campbell Barton
Date: Sat Oct 28 17:48:45 2017 +1100
Branches: master
https://developer.blender.org/rB8ac69ff9dcfc6aba8b5de8d53658612c8411b43b
Cleanup: use uint type in BLI
===================================================================
M source/blender/blenlib/intern/BLI_args.c
M source/blender/blenlib/intern/BLI_heap.c
M source/blender/blenlib/intern/BLI_kdopbvh.c
M source/blender/blenlib/intern/BLI_kdtree.c
M source/blender/blenlib/intern/BLI_mempool.c
M source/blender/blenlib/intern/boxpack2d.c
M source/blender/blenlib/intern/edgehash.c
M source/blender/blenlib/intern/fileops.c
M source/blender/blenlib/intern/path_util.c
M source/blender/blenlib/intern/smallhash.c
M source/blender/blenlib/intern/string_cursor_utf8.c
M source/blender/blenlib/intern/string_utf8.c
===================================================================
diff --git a/source/blender/blenlib/intern/BLI_args.c b/source/blender/blenlib/intern/BLI_args.c
index 340ae52120c..4eebcd46374 100644
--- a/source/blender/blenlib/intern/BLI_args.c
+++ b/source/blender/blenlib/intern/BLI_args.c
@@ -73,10 +73,10 @@ struct bArgs {
int *passes;
};
-static unsigned int case_strhash(const void *ptr)
+static uint case_strhash(const void *ptr)
{
const char *s = ptr;
- unsigned int i = 0;
+ uint i = 0;
unsigned char c;
while ( (c = tolower(*s++)) )
@@ -85,7 +85,7 @@ static unsigned int case_strhash(const void *ptr)
return i;
}
-static unsigned int keyhash(const void *ptr)
+static uint keyhash(const void *ptr)
{
const bAKey *k = ptr;
return case_strhash(k->arg); /* ^ BLI_ghashutil_inthash((void *)k->pass); */
diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c
index d7fd1caa8da..6b3d797a485 100644
--- a/source/blender/blenlib/intern/BLI_heap.c
+++ b/source/blender/blenlib/intern/BLI_heap.c
@@ -38,15 +38,15 @@
/***/
struct HeapNode {
- void *ptr;
- float value;
- unsigned int index;
+ void *ptr;
+ float value;
+ uint index;
};
struct HeapNode_Chunk {
struct HeapNode_Chunk *prev;
- unsigned int size;
- unsigned int bufsize;
+ uint size;
+ uint bufsize;
struct HeapNode buf[0];
};
@@ -58,11 +58,11 @@ struct HeapNode_Chunk {
* \note keep type in sync with tot_nodes in heap_node_alloc_chunk.
*/
#define HEAP_CHUNK_DEFAULT_NUM \
- ((unsigned int)((MEM_SIZE_OPTIMAL((1 << 16) - sizeof(struct HeapNode_Chunk))) / sizeof(HeapNode)))
+ ((uint)((MEM_SIZE_OPTIMAL((1 << 16) - sizeof(struct HeapNode_Chunk))) / sizeof(HeapNode)))
struct Heap {
- unsigned int size;
- unsigned int bufsize;
+ uint size;
+ uint bufsize;
HeapNode **tree;
struct {
@@ -85,16 +85,16 @@ struct Heap {
#define HEAP_EQUALS(a, b) ((a)->value == (b)->value)
#endif
-BLI_INLINE void heap_swap(Heap *heap, const unsigned int i, const unsigned int j)
+BLI_INLINE void heap_swap(Heap *heap, const uint i, const uint j)
{
#if 0
- SWAP(unsigned int, heap->tree[i]->index, heap->tree[j]->index);
+ SWAP(uint, heap->tree[i]->index, heap->tree[j]->index);
SWAP(HeapNode *, heap->tree[i], heap->tree[j]);
#else
HeapNode **tree = heap->tree;
union {
- unsigned int index;
+ uint index;
HeapNode *node;
} tmp;
SWAP_TVAL(tmp.index, tree[i]->index, tree[j]->index);
@@ -102,15 +102,15 @@ BLI_INLINE void heap_swap(Heap *heap, const unsigned int i, const unsigned int j
#endif
}
-static void heap_down(Heap *heap, unsigned int i)
+static void heap_down(Heap *heap, uint i)
{
/* size won't change in the loop */
- const unsigned int size = heap->size;
+ const uint size = heap->size;
while (1) {
- const unsigned int l = HEAP_LEFT(i);
- const unsigned int r = HEAP_RIGHT(i);
- unsigned int smallest;
+ const uint l = HEAP_LEFT(i);
+ const uint r = HEAP_RIGHT(i);
+ uint smallest;
smallest = ((l < size) && HEAP_COMPARE(heap->tree[l], heap->tree[i])) ? l : i;
@@ -127,10 +127,10 @@ static void heap_down(Heap *heap, unsigned int i)
}
}
-static void heap_up(Heap *heap, unsigned int i)
+static void heap_up(Heap *heap, uint i)
{
while (i > 0) {
- const unsigned int p = HEAP_PARENT(i);
+ const uint p = HEAP_PARENT(i);
if (HEAP_COMPARE(heap->tree[p], heap->tree[i])) {
break;
@@ -147,7 +147,7 @@ static void heap_up(Heap *heap, unsigned int i)
* \{ */
static struct HeapNode_Chunk *heap_node_alloc_chunk(
- unsigned int tot_nodes, struct HeapNode_Chunk *chunk_prev)
+ uint tot_nodes, struct HeapNode_Chunk *chunk_prev)
{
struct HeapNode_Chunk *chunk = MEM_mallocN(
sizeof(struct HeapNode_Chunk) + (sizeof(HeapNode) * tot_nodes), __func__);
@@ -189,7 +189,7 @@ static void heap_node_free(Heap *heap, HeapNode *node)
* \{ */
/* use when the size of the heap is known in advance */
-Heap *BLI_heap_new_ex(unsigned int tot_reserve)
+Heap *BLI_heap_new_ex(uint tot_reserve)
{
Heap *heap = MEM_mallocN(sizeof(Heap), __func__);
/* ensure we have at least one so we can keep doubling it */
@@ -211,7 +211,7 @@ Heap *BLI_heap_new(void)
void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp)
{
if (ptrfreefp) {
- unsigned int i;
+ uint i;
for (i = 0; i < heap->size; i++) {
ptrfreefp(heap->tree[i]->ptr);
@@ -233,7 +233,7 @@ void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp)
void BLI_heap_clear(Heap *heap, HeapFreeFP ptrfreefp)
{
if (ptrfreefp) {
- unsigned int i;
+ uint i;
for (i = 0; i < heap->size; i++) {
ptrfreefp(heap->tree[i]->ptr);
@@ -280,7 +280,7 @@ bool BLI_heap_is_empty(Heap *heap)
return (heap->size == 0);
}
-unsigned int BLI_heap_size(Heap *heap)
+uint BLI_heap_size(Heap *heap)
{
return heap->size;
}
@@ -308,12 +308,12 @@ void *BLI_heap_popmin(Heap *heap)
void BLI_heap_remove(Heap *heap, HeapNode *node)
{
- unsigned int i = node->index;
+ uint i = node->index;
BLI_assert(heap->size != 0);
while (i > 0) {
- unsigned int p = HEAP_PARENT(i);
+ uint p = HEAP_PARENT(i);
heap_swap(heap, p, i);
i = p;
diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c
index e5ca53a0193..bd16bc1a9c6 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -1294,7 +1294,7 @@ static void bvhtree_overlap_task_cb(void *userdata, const int j)
}
BVHTreeOverlap *BLI_bvhtree_overlap(
- const BVHTree *tree1, const BVHTree *tree2, unsigned int *r_overlap_tot,
+ const BVHTree *tree1, const BVHTree *tree2, uint *r_overlap_tot,
/* optional callback to test the overlap before adding (must be thread-safe!) */
BVHTree_OverlapCallback callback, void *userdata)
{
@@ -1351,13 +1351,13 @@ BVHTreeOverlap *BLI_bvhtree_overlap(
to = overlap = MEM_mallocN(sizeof(BVHTreeOverlap) * total, "BVHTreeOverlap");
for (j = 0; j < thread_num; j++) {
- unsigned int count = (unsigned int)BLI_stack_count(data[j].overlap);
+ uint count = (uint)BLI_stack_count(data[j].overlap);
BLI_stack_pop_n(data[j].overlap, to, count);
BLI_stack_free(data[j].overlap);
to += count;
}
- *r_overlap_tot = (unsigned int)total;
+ *r_overlap_tot = (uint)total;
return overlap;
}
diff --git a/source/blender/blenlib/intern/BLI_kdtree.c b/source/blender/blenlib/intern/BLI_kdtree.c
index 84ac339cc4d..844f274a81f 100644
--- a/source/blender/blenlib/intern/BLI_kdtree.c
+++ b/source/blender/blenlib/intern/BLI_kdtree.c
@@ -33,25 +33,25 @@
#include "BLI_strict_flags.h"
typedef struct KDTreeNode_head {
- unsigned int left, right;
+ uint left, right;
float co[3];
int index;
} KDTreeNode_head;
typedef struct KDTreeNode {
- unsigned int left, right;
+ uint left, right;
float co[3];
int index;
- unsigned int d; /* range is only (0-2) */
+ uint d; /* range is only (0-2) */
} KDTreeNode;
struct KDTree {
KDTreeNode *nodes;
- unsigned int totnode;
- unsigned int root;
+ uint totnode;
+ uint root;
#ifdef DEBUG
bool is_balanced; /* ensure we call balance first */
- unsigned int maxsize; /* max size of the tree */
+ uint maxsize; /* max size of the tree */
#endif
};
@@ -59,12 +59,12 @@ struct KDTree {
#define KD_NEAR_ALLOC_INC 100 /* alloc increment for collecting nearest */
#define KD_FOUND_ALLOC_INC 50 /* alloc increment for collecting nearest */
-#define KD_NODE_UNSET ((unsigned int)-1)
+#define KD_NODE_UNSET ((uint)-1)
/**
* Creates or free a kdtree
*/
-KDTree *BLI_kdtree_new(unsigned int maxsize)
+KDTree *BLI_kdtree_new(uint maxsize)
{
KDTree *tree;
@@ -113,11 +113,11 @@ void BLI_kdtree_insert(KDTree *tree, int index, const float co[3])
#endif
}
-static unsigned int kdtree_balance(KDTreeNode *nodes, unsigned int totnode, unsigned int axis, const unsigned int ofs)
+static uint kdtree_balance(KDTreeNode *nodes, uint totnode, uint axis, const uint ofs)
{
KDTreeNode *node;
float co;
- unsigned int left, right, median, i, j;
+ uint left, right, median, i, j;
if (totnode <= 0)
return KD_NODE_UNSET;
@@ -188,11 +188,11 @@ static float squared_distance(const float v2[3], const float v1[3], const float
return dist;
}
-static unsigned int *realloc_nodes(unsigned int *stack, unsigned int *totstack, const bool is_alloc)
+static uint *realloc_nodes(uint *stack, uint *totstack, const bool is_alloc)
{
- unsigned int *stack_new = MEM_mallocN((*totstack + KD_NEAR_ALLOC_INC) * sizeof(unsigned int), "KDTree.treestack");
- memcpy(stack_new, stack, *totstack * sizeof(unsigned int));
- // memset(stack_new + *totstack, 0, sizeof(unsigned int) * KD_NEAR_ALLOC_INC);
+ uint *stack_new = MEM_mallocN((*totstack + KD_NEAR_ALLOC_INC) * sizeof(uint), "KDTree.treestack");
+ memcpy(stack_new, stack, *totstack * sizeof(uint));
+ // memset(stack_new + *totstack, 0, sizeof(uint) * KD_NEAR_ALLOC_INC);
if (is_alloc)
MEM_freeN(stack);
*totstack += KD_NEAR_ALLOC_INC;
@@ -208,9 +208,9 @@ int BLI_kdtree_find_nearest(
{
const KDTreeNode *nodes = tree->nodes;
const KDTreeNode *root, *min_node;
- unsigned int *stack, defaultstack[KD_STACK_INIT];
+ uint *stack, defaultstack[KD_STACK_INIT];
float min_dist, cur_dist;
- unsigned int totstack, cur = 0;
+ uint totstack, cur = 0;
#ifdef DEBUG
BLI_assert(tree->is_balanced == true);
@@ -307,9 +307,9 @@ int BLI_kdtree_find_nearest_cb(
const KDTreeNode *nodes = tree->nodes;
const KDTreeNode *min_node = NULL;
- unsigned int *stack, defaultstack[KD_STACK_INIT];
+ uint *stack, defaultstack[KD_STACK_INIT];
float min_dist = FLT_MAX, cur_dist;
- unsigned int totstack, cur = 0;
+ uint totstack, cur = 0;
#ifdef DEBUG
BLI_assert(tree->is_balanced == true);
@@ -397,10 +397,10 @@ finally:
}
}
-static void add_nearest(KDTreeNearest *ptn, unsigned int *found, unsigned int n, int index,
+static void add_nearest(KDTreeNearest *ptn, uint *found, uint n, int index,
float dist, const float *co)
{
- unsigned int i;
+ uint i;
if (*found < n) (*found)++;
@@ -425,14 +425,14 @@ static void add_nearest(KDTreeNearest *ptn, unsigned int *found, unsigned int n,
int BLI_kdtree_find_nearest_n__normal(
const KDTree *tree, const float co[3], cons
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list