mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Revert "Speed up tail processing when hashing aligned C strings"
This reverts commit 07f0f6abfc
.
This has shown failures on both Valgrind and big-endian machines,
per members skink and pike.
This commit is contained in:
@@ -219,9 +219,8 @@ static inline size_t
|
|||||||
fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
|
fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
|
||||||
{
|
{
|
||||||
const char *const start = str;
|
const char *const start = str;
|
||||||
uint64 chunk;
|
size_t remainder;
|
||||||
uint64 zero_byte_low;
|
uint64 zero_byte_low;
|
||||||
uint64 mask;
|
|
||||||
|
|
||||||
Assert(PointerIsAligned(start, uint64));
|
Assert(PointerIsAligned(start, uint64));
|
||||||
|
|
||||||
@@ -240,7 +239,7 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
|
|||||||
*/
|
*/
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
chunk = *(uint64 *) str;
|
uint64 chunk = *(uint64 *) str;
|
||||||
|
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
zero_byte_low = haszero64(pg_bswap64(chunk));
|
zero_byte_low = haszero64(pg_bswap64(chunk));
|
||||||
@@ -255,37 +254,14 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
|
|||||||
str += FH_SIZEOF_ACCUM;
|
str += FH_SIZEOF_ACCUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zero_byte_low & 0xFF)
|
/*
|
||||||
{
|
* 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
|
||||||
* The next byte in the input is the NUL terminator, so we have
|
* position by dividing by 8.
|
||||||
* nothing to do.
|
*/
|
||||||
*/
|
remainder = pg_rightmost_one_pos64(zero_byte_low) / BITS_PER_BYTE;
|
||||||
}
|
fasthash_accum(hs, str, remainder);
|
||||||
else
|
str += remainder;
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Create a mask for the remaining bytes so we can combine them into
|
|
||||||
* the hash. The mask also covers the NUL terminator, but that's
|
|
||||||
* harmless. The mask could contain 0x80 in bytes corresponding to the
|
|
||||||
* input past the terminator, but only where the input byte is zero or
|
|
||||||
* one, so also harmless.
|
|
||||||
*/
|
|
||||||
mask = zero_byte_low | (zero_byte_low - 1);
|
|
||||||
#ifdef WORDS_BIGENDIAN
|
|
||||||
/* need to mask the upper bytes */
|
|
||||||
mask = pg_bswap64(mask);
|
|
||||||
#endif
|
|
||||||
hs->accum = chunk & mask;
|
|
||||||
fasthash_combine(hs);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The byte corresponding to the NUL will be 0x80, so the rightmost
|
|
||||||
* bit position will be in the range 15, 23, ..., 63. Turn this into
|
|
||||||
* byte position by dividing by 8.
|
|
||||||
*/
|
|
||||||
str += pg_rightmost_one_pos64(zero_byte_low) / BITS_PER_BYTE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str - start;
|
return str - start;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user