Rewrite loop to avoid final assert(0)
This commit is contained in:
1 parent
676b12d5d2
commit
095bf7070d
2 files changed
+6
-7
No files matched your search
+4
-3
@@ -926,12 +926,13 @@
|
|||||||
{ \
|
{ \
|
||||||
M_ASSERT (!M_C(name, _is_leaf)(parent)); \
|
M_ASSERT (!M_C(name, _is_leaf)(parent)); \
|
||||||
const int num = M_C(name, _get_num)(parent); \
|
const int num = M_C(name, _get_num)(parent); \
|
||||||
for(int i = 0; i <= num; i++) { \
|
int i = 0; \
|
||||||
|
while (true) { \
|
||||||
|
M_ASSERT(i <= num); \
|
||||||
if (parent->kind.node[i] == child) \
|
if (parent->kind.node[i] == child) \
|
||||||
return i; \
|
return i; \
|
||||||
|
i++; \
|
||||||
} \
|
} \
|
||||||
M_ASSERT(false); \
|
|
||||||
return -1; /* unreachable */ \
|
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline bool M_C(name, _erase)(tree_t b, key_t const key) \
|
static inline bool M_C(name, _erase)(tree_t b, key_t const key) \
|
||||||
|
|||||||
@@ -826,17 +826,15 @@
|
|||||||
const size_t index0 = d->front->index; \
|
const size_t index0 = d->front->index; \
|
||||||
size_t count = 0; \
|
size_t count = 0; \
|
||||||
/* This loop is in log(N) since the size increase exponentially.*/ \
|
/* This loop is in log(N) since the size increase exponentially.*/ \
|
||||||
for(node_t *n = d->front->node; \
|
for(node_t *n = d->front->node; true ; \
|
||||||
n != NULL ; \
|
|
||||||
n = (n == d->back->node) ? NULL : \
|
n = (n == d->back->node) ? NULL : \
|
||||||
M_C(name, _node_list_next_obj)(d->list, n) ){ \
|
M_C(name, _node_list_next_obj)(d->list, n) ){ \
|
||||||
|
M_ASSERT(n != NULL); \
|
||||||
if (index0 + key < count + n->size) { \
|
if (index0 + key < count + n->size) { \
|
||||||
return &n->data[index0 + key - count]; \
|
return &n->data[index0 + key - count]; \
|
||||||
} \
|
} \
|
||||||
count += n->size; \
|
count += n->size; \
|
||||||
} \
|
} \
|
||||||
M_ASSERT(false); \
|
|
||||||
return NULL; \
|
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline type const * \
|
static inline type const * \
|
||||||
|
|||||||
Reference in new issue
Block a user