summaryrefslogtreecommitdiffhomepage
path: root/libs/lmo/src
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2012-11-23 10:15:02 +0000
committerJo-Philipp Wich <jow@openwrt.org>2012-11-23 10:15:02 +0000
commitc647ff9f0e1af211a762dc9a773c1b5c4aacd168 (patch)
tree92437cfa3de24947a9f5d01519688236e0e3e7e3 /libs/lmo/src
parent5fdf5626699fac59d5c56d4f410d5e43e2c6e152 (diff)
libs/lmo: fix whitespace handling in string hashing, optimize code
Diffstat (limited to 'libs/lmo/src')
-rw-r--r--libs/lmo/src/lmo_lualib.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/libs/lmo/src/lmo_lualib.c b/libs/lmo/src/lmo_lualib.c
index ade8e01f7..5cc1e7d69 100644
--- a/libs/lmo/src/lmo_lualib.c
+++ b/libs/lmo/src/lmo_lualib.c
@@ -55,17 +55,12 @@ static uint32_t _lmo_hash_string(lua_State *L, int n) {
if (!str || len >= sizeof(res))
return 0;
- while (*str && isspace(*str))
- str++;
-
- for (prev = 0, ptr = res; *str; prev = *str, str++)
+ for (prev = ' ', ptr = res; *str; prev = *str, str++)
{
if (isspace(*str))
{
- if (isspace(prev))
- continue;
-
- *ptr++ = ' ';
+ if (!isspace(prev))
+ *ptr++ = ' ';
}
else
{
@@ -73,7 +68,7 @@ static uint32_t _lmo_hash_string(lua_State *L, int n) {
}
}
- while ((ptr > res) && isspace(*ptr))
+ if ((ptr > res) && isspace(*(ptr-1)))
ptr--;
return sfh_hash(res, ptr - res);