aboutsummaryrefslogtreecommitdiffstats
path: root/src/zrsh.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/zrsh.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/zrsh.c')
-rw-r--r--src/zrsh.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/zrsh.c b/src/zrsh.c
index 649ebb3..ebc00d7 100644
--- a/src/zrsh.c
+++ b/src/zrsh.c
@@ -1,9 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include "internals"
-#include <stdlib.h>
-#include <string.h>
-
void
zrsh(z_t a, z_t b, size_t bits)
@@ -11,8 +8,7 @@ zrsh(z_t a, z_t b, size_t bits)
size_t i, chars, cbits;
if (!bits) {
- if (a != b)
- zset(a, b);
+ SET(a, b);
return;
}
@@ -28,14 +24,12 @@ zrsh(z_t a, z_t b, size_t bits)
if (chars && a == b) {
a->used -= chars;
- memmove(a->chars, a->chars + chars, a->used * sizeof(*(a->chars)));
+ zmemmove(a->chars, a->chars + chars, a->used);
} else if (a != b) {
a->used = b->used - chars;
- if (a->alloced < a->used) {
- a->alloced = a->used;
- a->chars = realloc(a->chars, a->used * sizeof(*(a->chars)));
- }
- memcpy(a->chars, b->chars + chars, a->used * sizeof(*(a->chars)));
+ if (a->alloced < a->used)
+ zahl_realloc(a->chars, a->used);
+ zmemcpy(a->chars, b->chars + chars, a->used);
}
a->chars[0] >>= bits;