From 636be863c63858b33976cef734885376852a6788 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Wed, 23 Oct 2013 18:03:35 +0200 Subject: [PATCH] unicode: simplify hash_ucs4 and cmp_ucs4 Both are overly complex. Remove the boilerplate and redundant code. Signed-off-by: David Herrmann --- src/tsm_unicode.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/tsm_unicode.c b/src/tsm_unicode.c index 7214a5b..eb061a2 100644 --- a/src/tsm_unicode.c +++ b/src/tsm_unicode.c @@ -112,11 +112,8 @@ static unsigned int hash_ucs4(const void *key) size_t i; const uint32_t *ucs4 = key; - i = 0; - while (ucs4[i] <= TSM_UCS4_MAX) { + for (i = 0; ucs4[i] <= TSM_UCS4_MAX; ++i) val = val * 33 + ucs4[i]; - ++i; - } return val; } @@ -128,19 +125,12 @@ static bool cmp_ucs4(const void *a, const void *b) v1 = a; v2 = b; - i = 0; - while (1) { + for (i = 0; ; ++i) { if (v1[i] > TSM_UCS4_MAX && v2[i] > TSM_UCS4_MAX) return true; - if (v1[i] > TSM_UCS4_MAX && v2[i] <= TSM_UCS4_MAX) - return false; - if (v1[i] <= TSM_UCS4_MAX && v2[i] > TSM_UCS4_MAX) - return false; if (v1[i] != v2[i]) return false; - - ++i; } } -- 2.7.4