Fix unit test addition function to work in constant time
This commit is contained in:
@@ -9,10 +9,11 @@ typedef struct bh_unit_s
|
|||||||
} bh_unit_t;
|
} bh_unit_t;
|
||||||
|
|
||||||
static bh_unit_t *root = NULL;
|
static bh_unit_t *root = NULL;
|
||||||
|
static bh_unit_t *last = NULL;
|
||||||
|
|
||||||
void bh_unit_add(const char *name, bh_unit_cb_t func)
|
void bh_unit_add(const char *name, bh_unit_cb_t func)
|
||||||
{
|
{
|
||||||
bh_unit_t *unit, *current;
|
bh_unit_t *unit;
|
||||||
|
|
||||||
unit = malloc(sizeof(*unit));
|
unit = malloc(sizeof(*unit));
|
||||||
if (!unit)
|
if (!unit)
|
||||||
@@ -22,14 +23,11 @@ void bh_unit_add(const char *name, bh_unit_cb_t func)
|
|||||||
unit->func = func;
|
unit->func = func;
|
||||||
unit->next = NULL;
|
unit->next = NULL;
|
||||||
|
|
||||||
current = root;
|
if (last)
|
||||||
while (current && current->next)
|
last->next = unit;
|
||||||
current = current->next;
|
|
||||||
|
|
||||||
if (current)
|
|
||||||
current->next = unit;
|
|
||||||
else
|
else
|
||||||
root = unit;
|
root = unit;
|
||||||
|
last = unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bh_unit_run(void)
|
int bh_unit_run(void)
|
||||||
|
|||||||
Reference in New Issue
Block a user