summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Naylor2025-02-24 11:03:29 +0000
committerJohn Naylor2025-02-24 11:03:29 +0000
commit0600d276d485a8222eb6b571b08889c9f539e86f (patch)
tree5c1b085957b91c31b00f3e52d285e405313231af
parent2421e9a51d20bb83154e54a16ce628f9249fa907 (diff)
Silence warning in older versions of Valgrind
Due to misunderstanding on my part, commit 235328ee4 did not go far enough to silence older versions of Valgrind. For those, it was the bit scan that was problematic, not the subsequent bit-masking operation. To fix, use the unaligned path for the trailing bytes. Since we don't have a bit scan here anymore, also remove some comments and endian-specific coding around that. Reported-by: Anton A. Melnikov <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 17
-rw-r--r--src/include/common/hashfn_unstable.h26
1 files changed, 3 insertions, 23 deletions
diff --git a/src/include/common/hashfn_unstable.h b/src/include/common/hashfn_unstable.h
index e07c0226c1f..8818a0d360b 100644
--- a/src/include/common/hashfn_unstable.h
+++ b/src/include/common/hashfn_unstable.h
@@ -14,8 +14,6 @@
#ifndef HASHFN_UNSTABLE_H
#define HASHFN_UNSTABLE_H
-#include "port/pg_bitutils.h"
-#include "port/pg_bswap.h"
/*
* fasthash is a modification of code taken from
@@ -262,26 +260,13 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
/*
* For every chunk of input, check for zero bytes before mixing into the
- * hash. The chunk with zeros must contain the NUL terminator. We arrange
- * so that zero_byte_low tells us not only that a zero exists, but also
- * where it is, so we can hash the remainder of the string.
- *
- * The haszero64 calculation will set bits corresponding to the lowest
- * byte where a zero exists, so that suffices for little-endian machines.
- * For big-endian machines, we would need bits set for the highest zero
- * byte in the chunk, since the trailing junk past the terminator could
- * contain additional zeros. haszero64 does not give us that, so we
- * byteswap the chunk first.
+ * hash. The chunk with zeros must contain the NUL terminator.
*/
for (;;)
{
uint64 chunk = *(uint64 *) str;
-#ifdef WORDS_BIGENDIAN
- zero_byte_low = haszero64(pg_bswap64(chunk));
-#else
zero_byte_low = haszero64(chunk);
-#endif
if (zero_byte_low)
break;
@@ -290,13 +275,8 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
str += FH_SIZEOF_ACCUM;
}
- /*
- * The byte corresponding to the NUL will be 0x80, so the rightmost bit
- * position will be in the range 7, 15, ..., 63. Turn this into byte
- * position by dividing by 8.
- */
- remainder = pg_rightmost_one_pos64(zero_byte_low) / BITS_PER_BYTE;
- fasthash_accum(hs, str, remainder);
+ /* mix in remaining bytes */
+ remainder = fasthash_accum_cstring_unaligned(hs, str);
str += remainder;
return str - start;