diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-03-03 23:02:59 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-03-03 23:02:59 +0100 |
| commit | d6987458f21cf1890045f2606d0f8ec4d2225b44 (patch) | |
| tree | 90afabbea01b01c4dedcb41748eb534ce04fbf77 /src/zand.c | |
| parent | zsets: minor optimisation (diff) | |
| download | libzahl-d6987458f21cf1890045f2606d0f8ec4d2225b44.tar.gz libzahl-d6987458f21cf1890045f2606d0f8ec4d2225b44.tar.bz2 libzahl-d6987458f21cf1890045f2606d0f8ec4d2225b44.tar.xz | |
Cleanup and fix bug in ztrunc
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/zand.c')
| -rw-r--r-- | src/zand.c | 13 |
1 files changed, 4 insertions, 9 deletions
@@ -1,9 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include "internals" -#include <stdlib.h> -#include <string.h> - void zand(z_t a, z_t b, z_t c) @@ -15,7 +12,7 @@ zand(z_t a, z_t b, z_t c) return; } - n = b->used < c->used ? b->used : c->used; + n = MIN(b->used, c->used); while (n--) if (b->chars[n] & c->chars[n]) goto found_highest; @@ -31,11 +28,9 @@ found_highest: while (n--) a->chars[n] &= b->chars[n]; } else { - if (a->alloced < a->used) { - a->alloced = a->used; - a->chars = realloc(a->chars, a->used * sizeof(*(a->chars))); - } - memcpy(a->chars, c->chars, a->used * sizeof(*(a->chars))); + if (a->alloced < a->used) + zahl_realloc(a, a->used); + zmemcpy(a->chars, c->chars, a->used); while (n--) a->chars[n] &= b->chars[n]; } |
