libs/lmo: fix whitespace handling in string hashing, optimize code
This commit is contained in:
parent
5fdf562669
commit
c647ff9f0e
1 changed files with 4 additions and 9 deletions
|
@ -55,17 +55,12 @@ static uint32_t _lmo_hash_string(lua_State *L, int n) {
|
||||||
if (!str || len >= sizeof(res))
|
if (!str || len >= sizeof(res))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
while (*str && isspace(*str))
|
for (prev = ' ', ptr = res; *str; prev = *str, str++)
|
||||||
str++;
|
|
||||||
|
|
||||||
for (prev = 0, ptr = res; *str; prev = *str, str++)
|
|
||||||
{
|
{
|
||||||
if (isspace(*str))
|
if (isspace(*str))
|
||||||
{
|
{
|
||||||
if (isspace(prev))
|
if (!isspace(prev))
|
||||||
continue;
|
*ptr++ = ' ';
|
||||||
|
|
||||||
*ptr++ = ' ';
|
|
||||||
}
|
}
|
||||||
else
|
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--;
|
ptr--;
|
||||||
|
|
||||||
return sfh_hash(res, ptr - res);
|
return sfh_hash(res, ptr - res);
|
||||||
|
|
Loading…
Reference in a new issue