From fdc75a358e4c20116640c08f4e8ce7a09dc3cebd Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 7 May 2016 03:02:56 +0200 Subject: Optimisations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- zahl/inlines.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'zahl/inlines.h') diff --git a/zahl/inlines.h b/zahl/inlines.h index 9884812..c6ddc84 100644 --- a/zahl/inlines.h +++ b/zahl/inlines.h @@ -259,12 +259,16 @@ zsave(z_t a, void *buffer) { if (ZAHL_LIKELY(buffer)) { char *buf = buffer; - *((int *)buf) = a->sign, buf += sizeof(int); + *((long *)buf) = a->sign, buf += sizeof(long); /* Use `long` for alignment. */ *((size_t *)buf) = a->used, buf += sizeof(size_t); - if (ZAHL_LIKELY(!zzero(a))) + if (ZAHL_LIKELY(!zzero(a))) { + a->chars[a->used + 2] = 0; + a->chars[a->used + 1] = 0; + a->chars[a->used + 0] = 0; libzahl_memcpy((zahl_char_t *)buf, a->chars, a->used); + } } - return sizeof(int) + sizeof(size_t) + (zzero(a) ? 0 : a->used * sizeof(zahl_char_t)); + return sizeof(long) + sizeof(size_t) + (zzero(a) ? 0 : ((a->used + 3) & ~3) * sizeof(zahl_char_t)); } -- cgit v1.2.3-70-g09d2