From 9784a16d47158c61220356bfa9adc2639d86ecf2 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Fri, 26 Jun 2020 00:25:15 +0200 Subject: [PATCH] Get ride of modular arithmetic --- m-dict.h | 8 ++++---- m-genint.h | 2 +- m-string.h | 8 +++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/m-dict.h b/m-dict.h index 287eb7f1..afba0eba 100644 --- a/m-dict.h +++ b/m-dict.h @@ -1392,7 +1392,7 @@ typedef enum { return; \ } \ if (M_UNLIKELY (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ) ) { \ - size_t delPos = -1U; \ + size_t delPos = SIZE_MAX; \ if (M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_DELETED)) delPos = p; \ size_t s = 1U; \ do { \ @@ -1404,7 +1404,7 @@ typedef enum { assert (s <= dict->mask); \ if (M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_DELETED) && delPos == (size_t)-1) delPos = p; \ } while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ); \ - if (delPos != (size_t) -1U) { \ + if (delPos != SIZE_MAX) { \ p = delPos; \ dict->count_delete --; \ } \ @@ -1444,7 +1444,7 @@ typedef enum { return &data[p].M_IF(isSet)(key, value); \ } \ if (M_UNLIKELY (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ) ) { \ - size_t delPos = -1U; \ + size_t delPos = SIZE_MAX; \ if (M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_DELETED)) delPos = p; \ size_t s = 1U; \ do { \ @@ -1455,7 +1455,7 @@ typedef enum { assert (s <= dict->mask); \ if (M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_DELETED) && delPos == (size_t)-1) delPos = p; \ } while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ); \ - if (delPos != (size_t) -1U) { \ + if (delPos != SIZE_MAX) { \ p = delPos; \ dict->count_delete --; \ } \ diff --git a/m-genint.h b/m-genint.h index 0168fbd5..a81f6809 100644 --- a/m-genint.h +++ b/m-genint.h @@ -76,7 +76,7 @@ typedef struct genint_s { #define GENINT_ONE ((genint_limb_t)1) // Value returned in case of error (not integer available). -#define GENINT_ERROR (-1U) +#define GENINT_ERROR (UINT_MAX) /* 32 bits of the master mask are kept for handling the ABA problem. * NOTE: May be too much. 16 bits should be more than enough. TBC diff --git a/m-string.h b/m-string.h index d66b356d..8f80802c 100644 --- a/m-string.h +++ b/m-string.h @@ -1285,7 +1285,7 @@ typedef enum { typedef unsigned int string_unicode_t; /* Error in case of decoding */ -#define STRING_UNICODE_ERROR (-1U) +#define STRING_UNICODE_ERROR (UINT_MAX) /* UTF8 character classification: * @@ -1350,7 +1350,9 @@ stringi_utf8_valid_str_p(const char str[]) return true; } -/* Computer the number of unicode characters are represented in the UTF8 stream */ +/* Computer the number of unicode characters are represented in the UTF8 stream + Return SIZE_MAX (aka -1) in case of error + */ static inline size_t stringi_utf8_length(const char str[]) { @@ -1359,7 +1361,7 @@ stringi_utf8_length(const char str[]) string_unicode_t u = 0; while (*str) { stringi_utf8_decode(*str, &s, &u); - if (M_UNLIKELY (s == STRINGI_UTF8_ERROR)) return -1U; + if (M_UNLIKELY (s == STRINGI_UTF8_ERROR)) return SIZE_MAX; size += (s == STRINGI_UTF8_STARTING); str++; }