aboutsummaryrefslogtreecommitdiffstats
path: root/src/zand.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-03 23:02:59 +0100
committerMattias Andrée <maandree@kth.se>2016-03-03 23:02:59 +0100
commitd6987458f21cf1890045f2606d0f8ec4d2225b44 (patch)
tree90afabbea01b01c4dedcb41748eb534ce04fbf77 /src/zand.c
parentzsets: minor optimisation (diff)
downloadlibzahl-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.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/zand.c b/src/zand.c
index 950ad8e..a75abc5 100644
--- a/src/zand.c
+++ b/src/zand.c
@@ -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];
}