diff options
Diffstat (limited to 'include/al')
| -rw-r--r-- | include/al/array_typed.h | 9 | ||||
| -rw-r--r-- | include/al/atomic.h | 6 | ||||
| -rw-r--r-- | include/al/lib.h | 4 | ||||
| -rw-r--r-- | include/al/list.h | 11 | ||||
| -rw-r--r-- | include/al/str.h | 25 | ||||
| -rw-r--r-- | include/al/wstr.h | 15 |
6 files changed, 44 insertions, 26 deletions
diff --git a/include/al/array_typed.h b/include/al/array_typed.h index 5c77507..076f58f 100644 --- a/include/al/array_typed.h +++ b/include/al/array_typed.h @@ -88,8 +88,9 @@ } \ static inline void _al_array_reserve_internal(N, __VA_ARGS__)(array(N, __VA_ARGS__) *a, u32 size) \ { \ - if (a->alloc >= size) \ + if (a->alloc >= size) { \ return; \ + } \ size = size < al_grow_step ? al_next_power_of_two(size) : \ (size + al_grow_step) & ~al_grow_step; \ a->data = (T *)(!a->data ? al_malloc(sizeof(T) * size) : al_realloc(a->data, sizeof(T) * size)); \ @@ -145,12 +146,14 @@ AL_ARRAY_DEFINE_FUNCTIONS(N, T, S) \ static inline void al_array_reserve(N, S)(array(N, S) *a, u32 size) \ { \ - if (S >= size) \ + if (S >= size) { \ return; \ + } \ bool copy_inline = a->data == NULL; \ _al_array_reserve_internal(N, S)(a, size); \ - if (UNLIKELY(copy_inline)) \ + if (UNLIKELY(copy_inline)) { \ al_memcpy(a->data, a->inline_data, sizeof(T) * a->size); \ + } \ } #endif // _AL_ARRAY_TYPED_H diff --git a/include/al/atomic.h b/include/al/atomic.h index f30b6e8..39b0c25 100644 --- a/include/al/atomic.h +++ b/include/al/atomic.h @@ -77,8 +77,7 @@ static inline f32 _al_atomic_add_f32(atomic(f32) *a, f32 value, s32 order) (void)a; (void)value; (void)order; - al_assert(false); - return 0.f; + al_assert_and_return(0.f); } static inline f32 _al_atomic_sub_f32(atomic(f32) *a, f32 value, s32 order) @@ -86,8 +85,7 @@ static inline f32 _al_atomic_sub_f32(atomic(f32) *a, f32 value, s32 order) (void)a; (void)value; (void)order; - al_assert(false); - return 0.f; + al_assert_and_return(0.f); } #endif // _AL_ATOMIC_H diff --git a/include/al/lib.h b/include/al/lib.h index de5008c..30f54b0 100644 --- a/include/al/lib.h +++ b/include/al/lib.h @@ -2,6 +2,7 @@ #define _AL_LIB_H #include "types.h" +#include "macros.h" #define AL_USE_STDLIB //#define AL_MEMORY_TRACKING @@ -121,8 +122,9 @@ static inline void *al_memrchr(const void *s, s32 c, size_t n) const u8 *src = (const u8 *)s + n - 1; u8 d = (u8)c; while (n--) { - if (*src == d) + if (*src == d) { return (void *)src; + } src--; } return NULL; diff --git a/include/al/list.h b/include/al/list.h index 52628a4..333d2a4 100644 --- a/include/al/list.h +++ b/include/al/list.h @@ -93,16 +93,19 @@ } \ static inline list_##name *list_remove_##name(list_##name *l, list_##name *n) \ { \ - if (!l) return l; \ - else if (l == n) { \ - if (n->next) \ + if (!l) { \ + return l; \ + } else if (l == n) { \ + if (n->next) { \ n->next->prev = NULL; \ + } \ l = n->next; \ list_free_node_##name(n); \ } else { \ n->prev->next = n->next; \ - if (n->next) \ + if (n->next) { \ n->next->prev = n->prev; \ + } \ list_free_node_##name(n); \ } \ return l; \ diff --git a/include/al/str.h b/include/al/str.h index 8a7746e..74cf922 100644 --- a/include/al/str.h +++ b/include/al/str.h @@ -39,8 +39,9 @@ static inline void al_str_free(str *s) static inline u32 al_str_reserve(str *s, u32 size) { - if (size <= s->alloc) + if (size <= s->alloc) { return s->alloc; + } size = size < al_grow_step ? al_next_power_of_two(size) : (size + al_grow_step) & ~al_grow_step; @@ -111,8 +112,9 @@ static inline void al_str_prepend(str *s, str *c) static inline s32 al_str_cmp(str *s, str *c, u32 i, u32 len) { - if (i + len > s->len || len > c->len) + if (i + len > s->len || len > c->len) { return -1; + } return al_memcmp(&al_str_at(s, i), c->data, len); } @@ -124,28 +126,32 @@ static inline bool al_str_eq(str *s, str *c) static inline s32 al_str_find(str *s, char c) { char *loc = (char *)al_memchr(s->data, c, s->len); - if (!loc) return -1; + if (!loc) { + return -1; + } return (s32)(loc - s->data); } static inline s32 al_str_rfind(str *s, char c) { char *loc = (char *)al_memrchr(s->data, c, s->len); - if (!loc) return -1; + if (!loc) { + return -1; + } return (s32)(loc - s->data); } // extremely slow. static inline s32 al_str_find_str(str *s, str *c) { - if (c->len > s->len) + if (c->len > s->len) { return -1; + } for (u32 i = 0; i < s->len - c->len; i++) { - if (al_str_at(s, i) != al_str_at(c, 0)) - continue; - if (al_str_cmp(s, c, i, c->len) == 0) + if (al_str_at(s, i) == al_str_at(c, 0) && al_str_cmp(s, c, i, c->len) == 0) { return i; + } } return -1; @@ -154,8 +160,9 @@ static inline s32 al_str_find_str(str *s, str *c) static inline u32 al_str_hash(str *s) { u32 hash = 5381; - for (u32 i = 0; i < s->len; i++) + for (u32 i = 0; i < s->len; i++) { hash = ((hash << 5) + hash) + al_str_at(s, i); /* hash * 33 + c */ + } return hash; } diff --git a/include/al/wstr.h b/include/al/wstr.h index 765445b..561e236 100644 --- a/include/al/wstr.h +++ b/include/al/wstr.h @@ -45,8 +45,9 @@ static inline void al_wstr_free(wstr *w) static inline u32 al_wstr_reserve(wstr *w, u32 size) { - if (size <= w->alloc) + if (size <= w->alloc) { return w->alloc; + } size = size < al_grow_step ? al_next_power_of_two(size) : (size + al_grow_step) & ~al_grow_step; @@ -76,8 +77,9 @@ static inline bool al_wstr_from_cstr(wstr *w, char *c) #ifdef AL_HAVE_WIDE_STRING mbstate_t mbstate = { 0 }; size_t len = mbsrtowcs(NULL, (const char **)&c, 0, &mbstate); - if (len == (size_t)-1) + if (len == (size_t)-1) { return false; + } al_wstr_sized(w, (u32)(len + 1)); w->len = (u32)mbsrtowcs(w->data, (const char **)&c, len, &mbstate); al_assert(w->len == (u32)len); @@ -104,8 +106,9 @@ static inline bool al_wstr_to_str(wstr *w, str *s) wchar_t *data = w->data; mbstate_t mbstate = { 0 }; size_t len = wcsrtombs(NULL, (const wchar_t **)&w->data, 0, &mbstate); - if (len == (size_t)-1) + if (len == (size_t)-1) { return false; + } al_str_sized(s, (u32)len); // Excludes the null terminator. s->len = (u32)wcsrtombs(s->data, (const wchar_t **)&w->data, len, &mbstate); @@ -145,8 +148,9 @@ static inline s32 al_wstr_cmp(wstr *w, wstr *c, u32 start, u32 len) static inline s32 al_wstr_find(wstr *w, wchar_t c) { for (s32 i = 0; i < (s32)w->len; i++) { - if (al_wstr_at(w, i) == c) + if (al_wstr_at(w, i) == c) { return i; + } } return -1; } @@ -154,8 +158,9 @@ static inline s32 al_wstr_find(wstr *w, wchar_t c) static inline s32 al_wstr_rfind(wstr *w, wchar_t c) { for (s32 i = (s32)w->len - 1; i >= 0; i--) { - if (al_wstr_at(w, i) == c) + if (al_wstr_at(w, i) == c) { return i; + } } return -1; } |