Skip to content

Commit 0600d27

Browse files
committed
Silence warning in older versions of Valgrind
Due to misunderstanding on my part, commit 235328e 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 <a.melnikov@postgrespro.ru> Discussion: https://postgr.es/m/f3aa2d45-3b28-41c5-9499-a1bc30e0f8ec@postgrespro.ru Backpatch-through: 17
1 parent 2421e9a commit 0600d27

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

src/include/common/hashfn_unstable.h

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#ifndef HASHFN_UNSTABLE_H
1515
#define HASHFN_UNSTABLE_H
1616

17-
#include "port/pg_bitutils.h"
18-
#include "port/pg_bswap.h"
1917

2018
/*
2119
* fasthash is a modification of code taken from
@@ -262,26 +260,13 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
262260

263261
/*
264262
* For every chunk of input, check for zero bytes before mixing into the
265-
* hash. The chunk with zeros must contain the NUL terminator. We arrange
266-
* so that zero_byte_low tells us not only that a zero exists, but also
267-
* where it is, so we can hash the remainder of the string.
268-
*
269-
* The haszero64 calculation will set bits corresponding to the lowest
270-
* byte where a zero exists, so that suffices for little-endian machines.
271-
* For big-endian machines, we would need bits set for the highest zero
272-
* byte in the chunk, since the trailing junk past the terminator could
273-
* contain additional zeros. haszero64 does not give us that, so we
274-
* byteswap the chunk first.
263+
* hash. The chunk with zeros must contain the NUL terminator.
275264
*/
276265
for (;;)
277266
{
278267
uint64 chunk = *(uint64 *) str;
279268

280-
#ifdef WORDS_BIGENDIAN
281-
zero_byte_low = haszero64(pg_bswap64(chunk));
282-
#else
283269
zero_byte_low = haszero64(chunk);
284-
#endif
285270
if (zero_byte_low)
286271
break;
287272

@@ -290,13 +275,8 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
290275
str += FH_SIZEOF_ACCUM;
291276
}
292277

293-
/*
294-
* The byte corresponding to the NUL will be 0x80, so the rightmost bit
295-
* position will be in the range 7, 15, ..., 63. Turn this into byte
296-
* position by dividing by 8.
297-
*/
298-
remainder = pg_rightmost_one_pos64(zero_byte_low) / BITS_PER_BYTE;
299-
fasthash_accum(hs, str, remainder);
278+
/* mix in remaining bytes */
279+
remainder = fasthash_accum_cstring_unaligned(hs, str);
300280
str += remainder;
301281

302282
return str - start;

0 commit comments

Comments
 (0)