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;
|
||||
|
||||
static bh_unit_t *root = NULL;
|
||||
static bh_unit_t *last = NULL;
|
||||
|
||||
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));
|
||||
if (!unit)
|
||||
@@ -22,14 +23,11 @@ void bh_unit_add(const char *name, bh_unit_cb_t func)
|
||||
unit->func = func;
|
||||
unit->next = NULL;
|
||||
|
||||
current = root;
|
||||
while (current && current->next)
|
||||
current = current->next;
|
||||
|
||||
if (current)
|
||||
current->next = unit;
|
||||
if (last)
|
||||
last->next = unit;
|
||||
else
|
||||
root = unit;
|
||||
last = unit;
|
||||
}
|
||||
|
||||
int bh_unit_run(void)
|
||||
|
||||
Reference in New Issue
Block a user