commit 1ec80039288073294e3e61b0c680e9c95688e786
parent b2c44d8c961090c2773f3a98d12fcafc7f5c5b2b
Author: Mattias Andrée <maandree@kth.se>
Date: Mon, 14 Mar 2016 20:51:37 +0100
Optimise zswap
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat:
M | zahl.h | | | 20 | +++++++++++++++++++- |
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/zahl.h b/zahl.h
@@ -189,7 +189,6 @@ void zperror(const char *); /* Identical to perror(3p) except it sup
ZAHL_INLINE void zinit(z_t a) { a->alloced = 0; a->chars = 0; }
-ZAHL_INLINE void zswap(z_t a, z_t b) { z_t t; *t = *a; *a = *b; *b = *t; }
ZAHL_INLINE int zeven(z_t a) { return !a->sign || !(a->chars[0] & 1); }
ZAHL_INLINE int zodd(z_t a) { return a->sign && (a->chars[0] & 1); }
ZAHL_INLINE int zeven_nonzero(z_t a) { return !(a->chars[0] & 1); }
@@ -201,6 +200,25 @@ ZAHL_INLINE void zneg(z_t a, z_t b) { if (a != b) zset(a, b); a->sign = -a->si
ZAHL_INLINE void
+zswap(z_t a, z_t b)
+{
+ z_t t;
+ t->sign = a->sign;
+ a->sign = b->sign;
+ b->sign = t->sign;
+ t->used = b->used;
+ b->used = a->used;
+ a->used = t->used;
+ t->alloced = a->alloced;
+ a->alloced = b->alloced;
+ b->alloced = t->alloced;
+ t->chars = b->chars;
+ b->chars = a->chars;
+ a->chars = t->chars;
+}
+
+
+ZAHL_INLINE void
zseti(z_t a, int64_t b)
{
if (ZAHL_UNLIKELY(b >= 0)) {