diff options
Diffstat (limited to 'src/zlsh.c')
| -rw-r--r-- | src/zlsh.c | 25 |
1 files changed, 10 insertions, 15 deletions
@@ -1,9 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include "internals" -#include <stdlib.h> -#include <string.h> - void zlsh(z_t a, z_t b, size_t bits) @@ -16,8 +13,7 @@ zlsh(z_t a, z_t b, size_t bits) return; } if (!bits) { - if (a != b) - zset(a, b); + SET(a, b); return; } @@ -26,12 +22,13 @@ zlsh(z_t a, z_t b, size_t bits) cbits = BITS_PER_CHAR - 1 - bits; a->used = b->used + chars; - if (a->alloced < a->used) { - a->alloced = a->used; - a->chars = realloc(a->chars, a->used * sizeof(*(a->chars))); - } - (a == b ? memmove : memcpy)(a->chars + chars, b->chars, a->used * sizeof(*(a->chars))); - memset(a->chars, 0, chars * sizeof(*(a->chars))); + if (a->alloced < a->used) + zahl_realloc(a, a->used); + if (a == b) + zmemmove(a->chars + chars, b->chars, a->used); + else + zmemcpy(a->chars + chars, b->chars, a->used); + zmemset(a->chars, 0, chars); for (i = chars; i < a->used; i++) { carry[~i & 1] = a->chars[i] >> cbits; @@ -39,10 +36,8 @@ zlsh(z_t a, z_t b, size_t bits) a->chars[i] |= carry[i & 1]; } if (carry[i & 1]) { - if (a->alloced == a->used) { - a->alloced <<= 1; - a->chars = realloc(a->chars, a->alloced * sizeof(*(a->chars))); - } + if (a->alloced == a->used) + zahl_realloc(a, a->alloced << 1); a->chars[i] = carry[i & 1]; a->used++; } |
