diff options
author | David Robillard <d@drobilla.net> | 2020-08-13 17:26:00 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-08-13 17:26:00 +0200 |
commit | 4215a8ab7cc004c617b91a1628dbad3f19fbbe30 (patch) | |
tree | fbd27e5d1dd2e185a7bb9b054091cb47cea5c3fe | |
parent | d86638c91f89187f72afc532baf565ded0a29b7f (diff) | |
download | zix-4215a8ab7cc004c617b91a1628dbad3f19fbbe30.tar.gz zix-4215a8ab7cc004c617b91a1628dbad3f19fbbe30.tar.bz2 zix-4215a8ab7cc004c617b91a1628dbad3f19fbbe30.zip |
Shrink some code
-rw-r--r-- | test/btree_test.c | 16 | ||||
-rw-r--r-- | zix/ring.c | 4 | ||||
-rw-r--r-- | zix/thread.h | 14 |
3 files changed, 12 insertions, 22 deletions
diff --git a/test/btree_test.c b/test/btree_test.c index 67419be..7c470c0 100644 --- a/test/btree_test.c +++ b/test/btree_test.c @@ -40,10 +40,10 @@ unique_rand(size_t i) static const uint32_t prime = 4294967291; if (i >= prime) { return i; // Values >= prime are mapped to themselves - } else { - const uint64_t residue = ((uint64_t)i * i) % prime; - return (i <= prime / 2) ? residue : prime - residue; } + + const uint64_t residue = ((uint64_t)i * i) % prime; + return (i <= prime / 2) ? residue : prime - residue; } static int @@ -51,14 +51,8 @@ int_cmp(const void* a, const void* b, const void* ZIX_UNUSED(user_data)) { const uintptr_t ia = (uintptr_t)a; const uintptr_t ib = (uintptr_t)b; - // note the (ia - ib) trick here would overflow - if (ia == ib) { - return 0; - } else if (ia < ib) { - return -1; - } else { - return 1; - } + + return ia < ib ? -1 : ia > ib ? 1 : 0; } static uintptr_t @@ -173,9 +173,9 @@ zix_ring_read(ZixRing* ring, void* dst, uint32_t size) ZIX_READ_BARRIER(); ring->read_head = (r + size) & ring->size_mask; return size; - } else { - return 0; } + + return 0; } uint32_t diff --git a/zix/thread.h b/zix/thread.h index 2af0c5e..e2b59c4 100644 --- a/zix/thread.h +++ b/zix/thread.h @@ -101,17 +101,13 @@ zix_thread_create(ZixThread* thread, const int ret = pthread_create(thread, NULL, function, arg); pthread_attr_destroy(&attr); - if (ret == EAGAIN) { - return ZIX_STATUS_NO_MEM; - } else if (ret == EINVAL) { - return ZIX_STATUS_BAD_ARG; - } else if (ret == EPERM) { - return ZIX_STATUS_BAD_PERMS; - } else if (ret) { - return ZIX_STATUS_ERROR; + switch (ret) { + case EAGAIN: return ZIX_STATUS_NO_MEM; + case EINVAL: return ZIX_STATUS_BAD_ARG; + case EPERM: return ZIX_STATUS_BAD_PERMS; } - return ZIX_STATUS_SUCCESS; + return ret ? ZIX_STATUS_ERROR : ZIX_STATUS_SUCCESS; } static inline ZixStatus |