diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2018-08-01 18:24:43 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2018-08-05 23:08:13 -0700 |
commit | 5b1381006b715a93f226117f82b7b6dd81bfff5e (patch) | |
tree | 115b13f01c6178ae2127b11206865be08601a05e /examples | |
parent | 8ba2cdb6bdbee95703e1c6632fd8519a5e4a206e (diff) | |
download | zlib-5b1381006b715a93f226117f82b7b6dd81bfff5e.tar.gz |
Use inline function instead of macro for index in enough.c.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/enough.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/examples/enough.c b/examples/enough.c index 56ad63e..3f8c0d2 100644 --- a/examples/enough.c +++ b/examples/enough.c @@ -18,6 +18,7 @@ Clean up comparisons of different types Clean up code indentation 1.5 1 Aug 2018 Clean up code style and formatting + Use inline function instead of macro for index */ /* @@ -179,7 +180,10 @@ struct { } g; // Index function for num[] and done[]. -#define INDEX(i,j,k) (((size_t)((i-1)>>1)*((i-2)>>1)+(j>>1)-1)*(g.max-1)+k-1) +local inline size_t map(int i, int j, int k) { + return k - 1 + ((size_t)((i - 1) >> 1) * ((i - 2) >> 1) + (j >> 1) - 1) * + (g.max - 1); +} // Free allocated space. Uses globals code, num, and done. local void cleanup(void) { @@ -218,7 +222,7 @@ local big_t count(int syms, int len, int left) { assert(syms > left && left > 0 && len < g.max); // see if we've done this one already - index = INDEX(syms, left, len); + index = map(syms, left, len); got = g.num[index]; if (got) return got; // we have -- return the saved result @@ -264,7 +268,7 @@ local int beenhere(int syms, int len, int left, int mem, int rem) { char *vector; // new or enlarged bit vector // point to vector for (syms,left,len), bit in vector for (mem,rem) - index = INDEX(syms, left, len); + index = map(syms, left, len); mem -= 1 << g.root; offset = (mem >> 3) + rem; offset = ((offset * (offset + 1)) >> 1) + rem; @@ -416,7 +420,7 @@ local void enough(int syms) { for (left = 2; left < n; left += 2) { // look at all reachable (root + 1) bit nodes, and the // resulting codes (complete at root + 2 or more) - index = INDEX(n, left, g.root + 1); + index = map(n, left, g.root + 1); if (g.root + 1 < g.max && g.num[index]) // reachable node examine(n, g.root + 1, left, 1 << g.root, 0); |