diff options
| author | Mikhail Romanko <me@blankhex.com> | 2024-06-16 12:26:17 +0300 |
|---|---|---|
| committer | Mikhail Romanko <me@blankhex.com> | 2024-06-16 12:26:17 +0300 |
| commit | 9642630dd1401b57e76729daf7b2e55559d96b8d (patch) | |
| tree | 65c73ff15ce9b489ed979c75b5aa2e943f2041c7 | |
| parent | d8b9e97e0787f7672e35d66101f093c677929211 (diff) | |
| download | bhlib-old-9642630dd1401b57e76729daf7b2e55559d96b8d.tar.gz | |
Fix unit test addition function to work in constant time
| -rw-r--r-- | unit/src/unit.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/unit/src/unit.c b/unit/src/unit.c index 95de080..12d251e 100644 --- a/unit/src/unit.c +++ b/unit/src/unit.c @@ -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) |
