From: David Herrmann Date: Wed, 23 Oct 2013 16:03:35 +0000 (+0200) Subject: unicode: simplify hash_ucs4 and cmp_ucs4 X-Git-Tag: upstream/3.0~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=636be863c63858b33976cef734885376852a6788;p=platform%2Fupstream%2Flibtsm.git unicode: simplify hash_ucs4 and cmp_ucs4 Both are overly complex. Remove the boilerplate and redundant code. Signed-off-by: David Herrmann --- 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; } }