summaryrefslogtreecommitdiff
path: root/src/hash.c
diff options
context:
space:
mode:
authorJustine Tunney <jtunney@gmail.com>2022-11-06 12:13:21 -0500
committerPaul Smith <psmith@gnu.org>2022-11-13 10:38:50 -0500
commit090d99dd2da676074145f64bce940f3867c613f1 (patch)
treea7648ffcde1900470f387ac8617250921b9d4e59 /src/hash.c
parent6b45f89adb44527ece9d28dfb5d7365ee28d711d (diff)
downloadmake-git-090d99dd2da676074145f64bce940f3867c613f1.tar.gz
* src/hash.c (jhash_string): Help the compiler optimize the hash
Invoke memcpy() with a constant length, where possible. Copyright-paperwork-exempt: yes
Diffstat (limited to 'src/hash.c')
-rw-r--r--src/hash.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/hash.c b/src/hash.c
index 5d7ea81b..d1652f84 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -361,7 +361,7 @@ round_up_2 (unsigned long n)
#define sum_get_unaligned_32(r, p) \
do { \
unsigned int val; \
- memcpy(&val, (p), 4); \
+ memcpy (&val, (p), 4); \
r += val; \
} while(0);
@@ -413,13 +413,16 @@ jhash(unsigned const char *k, int length)
#define UINTSZ sizeof (unsigned int)
#ifdef WORDS_BIGENDIAN
-/* The ifs are ordered from the first byte in memory to the last. */
+/* The ifs are ordered from the first byte in memory to the last.
+ Help the compiler optimize by using static memcpy length. */
#define sum_up_to_nul(r, p, plen, flag) \
do { \
unsigned int val = 0; \
size_t pn = (plen); \
- size_t n = pn < UINTSZ ? pn : UINTSZ; \
- memcpy (&val, (p), n); \
+ if (pn >= UINTSZ) \
+ memcpy (&val, (p), UINTSZ); \
+ else \
+ memcpy (&val, (p), pn); \
if ((val & 0xFF000000) == 0) \
flag = 1; \
else if ((val & 0xFF0000) == 0) \
@@ -432,13 +435,16 @@ jhash(unsigned const char *k, int length)
#else
/* First detect the presence of zeroes. If there is none, we can
sum the 4 bytes directly. Otherwise, the ifs are ordered as in the
- big endian case, from the first byte in memory to the last. */
+ big endian case, from the first byte in memory to the last.
+ Help the compiler optimize by using static memcpy length. */
#define sum_up_to_nul(r, p, plen, flag) \
do { \
unsigned int val = 0; \
size_t pn = (plen); \
- size_t n = pn < UINTSZ ? pn : UINTSZ; \
- memcpy (&val, (p), n); \
+ if (pn >= UINTSZ) \
+ memcpy (&val, (p), UINTSZ); \
+ else \
+ memcpy (&val, (p), pn); \
flag = ((val - 0x01010101) & ~val) & 0x80808080; \
if (!flag) \
r += val; \