Rewrite loop to avoid final assert(0)

This commit is contained in:
Patrick Pelissier committed 2023-04-06 21:55:06 +02:00
1 parent 676b12d5d2
commit 095bf7070d
2 files changed
+6 -7

No files matched your search

+4 -3
View File
@@ -926,12 +926,13 @@
{ \
M_ASSERT (!M_C(name, _is_leaf)(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) \
return i; \
i++; \
} \
M_ASSERT(false); \
return -1; /* unreachable */ \
} \
\
static inline bool M_C(name, _erase)(tree_t b, key_t const key) \
+2 -4
View File
@@ -826,17 +826,15 @@
const size_t index0 = d->front->index; \
size_t count = 0; \
/* This loop is in log(N) since the size increase exponentially.*/ \
for(node_t *n = d->front->node; \
n != NULL ; \
for(node_t *n = d->front->node; true ; \
n = (n == d->back->node) ? NULL : \
M_C(name, _node_list_next_obj)(d->list, n) ){ \
M_ASSERT(n != NULL); \
if (index0 + key < count + n->size) { \
return &n->data[index0 + key - count]; \
} \
count += n->size; \
} \
M_ASSERT(false); \
return NULL; \
} \
\
static inline type const * \