diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-03-13 05:30:01 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-03-13 05:30:01 +0100 |
| commit | f6cb7f3e7382a19a6d6d9990c243ffb8a666182d (patch) | |
| tree | dbf43f976f66a39fd87ffa38d59194b425efaa68 /src/zrsh.c | |
| parent | Make zabs, zneg and zswap inline (diff) | |
| download | libzahl-f6cb7f3e7382a19a6d6d9990c243ffb8a666182d.tar.gz libzahl-f6cb7f3e7382a19a6d6d9990c243ffb8a666182d.tar.bz2 libzahl-f6cb7f3e7382a19a6d6d9990c243ffb8a666182d.tar.xz | |
Optimisations
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/zrsh.c')
| -rw-r--r-- | src/zrsh.c | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -7,14 +7,14 @@ zrsh(z_t a, z_t b, size_t bits) { size_t i, chars, cbits; - if (!bits) { + if (EXPECT(!bits, 0)) { SET(a, b); return; } chars = FLOOR_BITS_TO_CHARS(bits); - if (zzero(b) || chars >= b->used || zbits(b) <= bits) { + if (EXPECT(zzero(b) || chars >= b->used || zbits(b) <= bits, 0)) { SET_SIGNUM(a, 0); return; } @@ -22,23 +22,22 @@ zrsh(z_t a, z_t b, size_t bits) bits = BITS_IN_LAST_CHAR(bits); cbits = BITS_PER_CHAR - bits; - if (chars && a == b) { + if (EXPECT(chars, 1) && EXPECT(a == b, 1)) { a->used -= chars; zmemmove(a->chars, a->chars + chars, a->used); - } else if (a != b) { + } else if (EXPECT(a != b, 0)) { a->used = b->used - chars; ENSURE_SIZE(a, a->used); zmemcpy(a->chars, b->chars + chars, a->used); } - if (bits) { /* This if statement is very important in C. */ + if (EXPECT(bits, 0)) { /* This if statement is very important in C. */ a->chars[0] >>= bits; for (i = 1; i < a->used; i++) { a->chars[i - 1] |= a->chars[i] << cbits; a->chars[i] >>= bits; } - while (!a->chars[a->used - 1]) - a->used--; + TRIM_NONZERO(a); } SET_SIGNUM(a, zsignum(b)); |
