Skip to content

Commit f4ad002

Browse files
committed
Revert "Speed up tail processing when hashing aligned C strings"
This reverts commit 07f0f6a. This has shown failures on both Valgrind and big-endian machines, per members skink and pike.
1 parent 07f0f6a commit f4ad002

File tree

1 file changed

+10
-34
lines changed

1 file changed

+10
-34
lines changed

src/include/common/hashfn_unstable.h

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,8 @@ static inline size_t
219219
fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
220220
{
221221
const char *const start = str;
222-
uint64 chunk;
222+
size_t remainder;
223223
uint64 zero_byte_low;
224-
uint64 mask;
225224

226225
Assert(PointerIsAligned(start, uint64));
227226

@@ -240,7 +239,7 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
240239
*/
241240
for (;;)
242241
{
243-
chunk = *(uint64 *) str;
242+
uint64 chunk = *(uint64 *) str;
244243

245244
#ifdef WORDS_BIGENDIAN
246245
zero_byte_low = haszero64(pg_bswap64(chunk));
@@ -255,37 +254,14 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
255254
str += FH_SIZEOF_ACCUM;
256255
}
257256

258-
if (zero_byte_low & 0xFF)
259-
{
260-
/*
261-
* The next byte in the input is the NUL terminator, so we have
262-
* nothing to do.
263-
*/
264-
}
265-
else
266-
{
267-
/*
268-
* Create a mask for the remaining bytes so we can combine them into
269-
* the hash. The mask also covers the NUL terminator, but that's
270-
* harmless. The mask could contain 0x80 in bytes corresponding to the
271-
* input past the terminator, but only where the input byte is zero or
272-
* one, so also harmless.
273-
*/
274-
mask = zero_byte_low | (zero_byte_low - 1);
275-
#ifdef WORDS_BIGENDIAN
276-
/* need to mask the upper bytes */
277-
mask = pg_bswap64(mask);
278-
#endif
279-
hs->accum = chunk & mask;
280-
fasthash_combine(hs);
281-
282-
/*
283-
* The byte corresponding to the NUL will be 0x80, so the rightmost
284-
* bit position will be in the range 15, 23, ..., 63. Turn this into
285-
* byte position by dividing by 8.
286-
*/
287-
str += pg_rightmost_one_pos64(zero_byte_low) / BITS_PER_BYTE;
288-
}
257+
/*
258+
* The byte corresponding to the NUL will be 0x80, so the rightmost bit
259+
* position will be in the range 7, 15, ..., 63. Turn this into byte
260+
* position by dividing by 8.
261+
*/
262+
remainder = pg_rightmost_one_pos64(zero_byte_low) / BITS_PER_BYTE;
263+
fasthash_accum(hs, str, remainder);
264+
str += remainder;
289265

290266
return str - start;
291267
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy