commit 58baaf9eaa1a0519766b9f5aabb510e1e6969d6c
Author:     Mattias Andrée <[email protected]>
AuthorDate: Sun Mar 13 01:04:48 2016 +0100
Commit:     Mattias Andrée <[email protected]>
CommitDate: Sun Mar 13 01:05:00 2016 +0100

    Make zabs, zneg and zswap inline
    
    Signed-off-by: Mattias Andrée <[email protected]>

diff --git a/Makefile b/Makefile
index 90351d9..c7c5822 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,6 @@ HDR =\
        src/internals.h
 
 FUN =\
-       zabs\
        zadd\
        zand\
        zbits\
@@ -29,7 +28,6 @@ FUN =\
        zmodpowu\
        zmodsqr\
        zmul\
-       zneg\
        znot\
        zor\
        zperror\
@@ -49,19 +47,21 @@ FUN =\
        zstr\
        zstr_length\
        zsub\
-       zswap\
        ztrunc\
        zunsetup\
        zxor
 
 INLINE_FUN =\
        zinit\
+       zswap\
        zeven\
        zodd\
        zeven_nonzero\
        zodd_nonzero\
        zzero\
-       zsignum
+       zsignum\
+       zabs\
+       zneg
 
 OBJ = $(FUN:=.o) allocator.o
 MAN3 = $(FUN:=.3) $(INLINE_FUN:=.3)
diff --git a/src/zabs.c b/src/zabs.c
deleted file mode 100644
index d4de6c4..0000000
--- a/src/zabs.c
+++ /dev/null
@@ -1,10 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include "internals.h"
-
-
-void
-zabs(z_t a, z_t b)
-{
-       SET(a, b);
-       SET_SIGNUM(a, !zzero(a));
-}
diff --git a/src/zneg.c b/src/zneg.c
deleted file mode 100644
index 484d610..0000000
--- a/src/zneg.c
+++ /dev/null
@@ -1,10 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include "internals.h"
-
-
-void
-zneg(z_t a, z_t b)
-{
-       SET(a, b);
-       SET_SIGNUM(a, -zsignum(a));
-}
diff --git a/src/zswap.c b/src/zswap.c
deleted file mode 100644
index 452d712..0000000
--- a/src/zswap.c
+++ /dev/null
@@ -1,12 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include "internals.h"
-
-
-void
-zswap(z_t a, z_t b)
-{
-       z_t t;
-       *t = *a;
-       *a = *b;
-       *b = *t;
-}
diff --git a/zahl.h b/zahl.h
index f537c23..9d2e654 100644
--- a/zahl.h
+++ b/zahl.h
@@ -44,7 +44,6 @@ void zunsetup(void);                   /* Free resources used 
by libzahl */
 /* Memory functions. */
 
 void zfree(z_t);                       /* Free resources in a. */
-void zswap(z_t, z_t);                  /* (a, b) := (b, a) */
 size_t zsave(z_t, void *);             /* Store a into b (if !!b), and return 
number of written bytes. */
 size_t zload(z_t, const void *);       /* Restore a from b, and return number 
of read bytes. */
 
@@ -78,8 +77,6 @@ void zdivmod(z_t, z_t, z_t, z_t);      /* a := c / d, b = c % 
d */
 void zmod(z_t, z_t, z_t);              /* a := b % c */
 void zsqr(z_t, z_t);                   /* a := b² */
 void zmodsqr(z_t, z_t, z_t);           /* a := b² % c */
-void zneg(z_t, z_t);                   /* a := -b */
-void zabs(z_t, z_t);                   /* a := |b| */
 void zpow(z_t, z_t, z_t);              /* a := b ↑ c */
 void zmodpow(z_t, z_t, z_t, z_t);      /* a := (b ↑ c) % d */
 void zpowu(z_t, z_t, unsigned long long int);
@@ -140,10 +137,13 @@ void zperror(const char *);            /* Identical to 
perror(3p) except it supp
 
 /* Inline functions. */
 
-static inline void zinit(z_t a)        { a->alloced = 0; a->chars = 0; }       
   /* Prepare a for use. */
-static inline int zeven(z_t a)         { return !a->sign || !(a->chars[0] & 
1); } /* Is a even? */
-static inline int zodd(z_t a)          { return a->sign && (a->chars[0] & 1); 
}   /* Is a odd? */
-static inline int zeven_nonzero(z_t a) { return !(a->chars[0] & 1); }          
   /* Is a even? Assumes a ≠ 0. */
-static inline int zodd_nonzero(z_t a)  { return (a->chars[0] & 1); }           
   /* Is a odd? Assumes a ≠ 0. */
-static inline int zzero(z_t a)         { return !a->sign; }                    
   /* Is a zero? */
-static inline int zsignum(z_t a)       { return a->sign; }                     
   /* a/|a|, 0 if a is zero. */
+static inline void zinit(z_t a)        { a->alloced = 0; a->chars = 0; }       
     /* Prepare a for use. */
+static inline void zswap(z_t a, z_t b) { z_t t; *t = *a; *a = *b; *b = *t; }   
     /* (a, b) := (b, a) */
+static inline int zeven(z_t a)         { return !a->sign || !(a->chars[0] & 
1); }   /* Is a even? */
+static inline int zodd(z_t a)          { return a->sign && (a->chars[0] & 1); 
}     /* Is a odd? */
+static inline int zeven_nonzero(z_t a) { return !(a->chars[0] & 1); }          
     /* Is a even? Assumes a ≠ 0. */
+static inline int zodd_nonzero(z_t a)  { return (a->chars[0] & 1); }           
     /* Is a odd? Assumes a ≠ 0. */
+static inline int zzero(z_t a)         { return !a->sign; }                    
     /* Is a zero? */
+static inline int zsignum(z_t a)       { return a->sign; }                     
     /* a/|a|, 0 if a is zero. */
+static inline void zabs(z_t a, z_t b)  { if (a != b) zset(a, b); a->sign = 
!!a->sign; }  /* a := |b| */
+static inline void zneg(z_t a, z_t b)  { if (a != b) zset(a, b); a->sign = 
-a->sign; }   /* a := -b */

Reply via email to