Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit235328e

Browse files
committed
Revert "Speed up tail processing when hashing aligned C strings, take two"
This reverts commita365d9e.Older versions of Valgrind raise an error, so go back to the bytewiseloop for the final word in the input.Reported-by: Anton A. Melnikov <a.melnikov@postgrespro.ru>Discussion:https://postgr.es/m/a3a959f6-14b8-4819-ac04-eaf2aa2e868d@postgrespro.ruBackpatch-through: 17
1 parent4f07134 commit235328e

File tree

1 file changed

+10
-36
lines changed

1 file changed

+10
-36
lines changed

‎src/include/common/hashfn_unstable.h

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,6 @@ fasthash_accum(fasthash_state *hs, const char *k, size_t len)
219219
#definehaszero64(v) \
220220
(((v) - 0x0101010101010101) & ~(v) & 0x8080808080808080)
221221

222-
/* get first byte in memory order */
223-
#ifdefWORDS_BIGENDIAN
224-
#definefirstbyte64(v) ((v) >> 56)
225-
#else
226-
#definefirstbyte64(v) ((v) & 0xFF)
227-
#endif
228-
229222
/*
230223
* all-purpose workhorse for fasthash_accum_cstring
231224
*/
@@ -262,7 +255,7 @@ static inline size_t
262255
fasthash_accum_cstring_aligned(fasthash_state*hs,constchar*str)
263256
{
264257
constchar*conststart=str;
265-
uint64chunk;
258+
size_tremainder;
266259
uint64zero_byte_low;
267260

268261
Assert(PointerIsAligned(start,uint64));
@@ -282,7 +275,7 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
282275
*/
283276
for (;;)
284277
{
285-
chunk=*(uint64*)str;
278+
uint64chunk=*(uint64*)str;
286279

287280
#ifdefWORDS_BIGENDIAN
288281
zero_byte_low=haszero64(pg_bswap64(chunk));
@@ -297,33 +290,14 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
297290
str+=FH_SIZEOF_ACCUM;
298291
}
299292

300-
if (firstbyte64(chunk)!=0)
301-
{
302-
size_tremainder;
303-
uint64mask;
304-
305-
/*
306-
* The byte corresponding to the NUL will be 0x80, so the rightmost
307-
* bit position will be in the range 15, 23, ..., 63. Turn this into
308-
* byte position by dividing by 8.
309-
*/
310-
remainder=pg_rightmost_one_pos64(zero_byte_low) /BITS_PER_BYTE;
311-
312-
/*
313-
* Create a mask for the remaining bytes so we can combine them into
314-
* the hash. This must have the same result as mixing the remaining
315-
* bytes with fasthash_accum().
316-
*/
317-
#ifdefWORDS_BIGENDIAN
318-
mask= ~UINT64CONST(0) <<BITS_PER_BYTE* (FH_SIZEOF_ACCUM-remainder);
319-
#else
320-
mask= ~UINT64CONST(0) >>BITS_PER_BYTE* (FH_SIZEOF_ACCUM-remainder);
321-
#endif
322-
hs->accum=chunk&mask;
323-
fasthash_combine(hs);
324-
325-
str+=remainder;
326-
}
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);
300+
str+=remainder;
327301

328302
returnstr-start;
329303
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp