]> git.ipfire.org Git - thirdparty/make.git/commitdiff
hash: Remove unnecessary isupper() check before tolower()
authorNoah Goldstein <goldstein.w.n@gmail.com>
Sun, 24 Apr 2022 21:39:35 +0000 (17:39 -0400)
committerPaul Smith <psmith@gnu.org>
Sun, 24 Apr 2022 21:52:54 +0000 (17:52 -0400)
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.

src/hash.h

index 667d6508267065630284c51ff678aab5689966be..f5b9362a1be2c84627a98eef495ad7826e54822c 100644 (file)
@@ -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; \