From: Noah Goldstein Date: Sun, 24 Apr 2022 21:39:35 +0000 (-0400) Subject: hash: Remove unnecessary isupper() check before tolower() X-Git-Tag: 4.3.90~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fa63eb918e965d6704f33c1b124d14357af9911;p=thirdparty%2Fmake.git hash: Remove unnecessary isupper() check before tolower() The standard requires that tolower() returns its argument if there's no valid lowercase conversion: it's not necessary to check isupper() before invoking tolower(). Comparing the performance of the old ISTRING_HASH to the new one on all the files present in GLIBC. Data Type Old Time New Time Alternating case 24985.754 13883.422 random case 35211.777 13569.051 all lower 18818.974 13706.645 all upper 38859.454 13506.315 * src/hash.h (ISTRING_HASH_1): Omit isupper() check. (ISTRING_HASH_2): Ditto. --- diff --git a/src/hash.h b/src/hash.h index 667d6508..f5b9362a 100644 --- a/src/hash.h +++ b/src/hash.h @@ -56,9 +56,9 @@ struct hash_table typedef int (*qsort_cmp_t) __P((void const *, void const *)); void hash_init __P((struct hash_table *ht, unsigned long size, - hash_func_t hash_1, hash_func_t hash_2, hash_cmp_func_t hash_cmp)); + hash_func_t hash_1, hash_func_t hash_2, hash_cmp_func_t hash_cmp)); void hash_load __P((struct hash_table *ht, void *item_table, - unsigned long cardinality, unsigned long size)); + unsigned long cardinality, unsigned long size)); void **hash_find_slot __P((struct hash_table *ht, void const *key)); void *hash_find_item __P((struct hash_table *ht, void const *key)); void *hash_insert __P((struct hash_table *ht, const void *item)); @@ -154,7 +154,7 @@ extern void *hash_deleted_item; #define ISTRING_HASH_1(KEY, RESULT) do { \ unsigned char const *_key_ = (unsigned char const *) (KEY) - 1; \ while (*++_key_) \ - (RESULT) += ((isupper (*_key_) ? tolower (*_key_) : *_key_) << (_key_[1] & 0xf)); \ + (RESULT) += (tolower (*_key_) << (_key_[1] & 0xf)); \ } while (0) #define return_ISTRING_HASH_1(KEY) do { \ unsigned long _result_ = 0; \ @@ -165,7 +165,7 @@ extern void *hash_deleted_item; #define ISTRING_HASH_2(KEY, RESULT) do { \ unsigned char const *_key_ = (unsigned char const *) (KEY) - 1; \ while (*++_key_) \ - (RESULT) += ((isupper (*_key_) ? tolower (*_key_) : *_key_) << (_key_[1] & 0x7)); \ + (RESULT) += (tolower (*_key_) << (_key_[1] & 0x7)); \ } while (0) #define return_ISTRING_HASH_2(KEY) do { \ unsigned long _result_ = 0; \