(hash_string): Rewrite to avoid cast.

This commit is contained in:
Paul Eggert 2004-08-02 22:49:34 +00:00
parent 28730b8b36
commit d5905bb653

View File

@ -1,7 +1,7 @@
/* hash - hashing table processing. /* hash - hashing table processing.
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free
Foundation, Inc. Software Foundation, Inc.
Written by Jim Meyering, 1992. Written by Jim Meyering, 1992.
@ -400,9 +400,10 @@ hash_string (const char *string, size_t n_buckets)
((Byte) + ROTATE_LEFT (Value, 7)) ((Byte) + ROTATE_LEFT (Value, 7))
size_t value = 0; size_t value = 0;
unsigned char ch;
for (; *string; string++) for (; (ch = *string); string++)
value = HASH_ONE_CHAR (value, (unsigned char) *string); value = HASH_ONE_CHAR (value, ch);
return value % n_buckets; return value % n_buckets;
# undef ROTATE_LEFT # undef ROTATE_LEFT
@ -420,9 +421,10 @@ size_t
hash_string (const char *string, size_t n_buckets) hash_string (const char *string, size_t n_buckets)
{ {
size_t value = 0; size_t value = 0;
unsigned char ch;
while (*string) for (; (ch = *string); string++)
value = (value * 31 + (unsigned char) *string++) % n_buckets; value = (value * 31 + ch) % n_buckets;
return value; return value;
} }