summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2013-10-23 18:03:35 +0200
committerDavid Herrmann <dh.herrmann@gmail.com>2013-10-23 18:03:35 +0200
commit636be863c63858b33976cef734885376852a6788 (patch)
treefc371d14cd172a76cde98b4f52998ba09064aac1
parent7eac13c7804e07b3aa22c2965ea956178fdf0c73 (diff)
unicode: simplify hash_ucs4 and cmp_ucs4
Both are overly complex. Remove the boilerplate and redundant code. Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
-rw-r--r--src/tsm_unicode.c14
1 files 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;
}
}