From e08cc93238e647c8d13ecd6acaaa85ab7bca9ec2 Mon Sep 17 00:00:00 2001 From: John Naylor Date: Wed, 24 Feb 2021 11:52:58 -0400 Subject: [PATCH v6 4/4] Widen the ASCII fast path stride in the fallback UTF-8 validator from 8 to 16 bytes. --- src/include/port/pg_utf8.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/include/port/pg_utf8.h b/src/include/port/pg_utf8.h index a19fc55c1e..89132243b0 100644 --- a/src/include/port/pg_utf8.h +++ b/src/include/port/pg_utf8.h @@ -58,22 +58,24 @@ extern int pg_validate_utf8_fallback(const unsigned char *s, int len); static inline int check_ascii(const unsigned char *s, int len) { - uint64 chunk, + uint64 half1, + half2, highbits_set; - if (len >= sizeof(uint64)) + if (len >= 2 * sizeof(uint64)) { - memcpy(&chunk, s, sizeof(uint64)); + memcpy(&half1, s, sizeof(uint64)); + memcpy(&half2, s + sizeof(uint64), sizeof(uint64)); /* If there are zero bytes, bail and let the slow path handle it. */ - if (HAS_ZERO(chunk)) + if (HAS_ZERO(half1) || HAS_ZERO(half2)) return 0; /* Check if any bytes in this chunk have the high bit set. */ - highbits_set = (chunk & UINT64CONST(0x8080808080808080)); + highbits_set = ((half1 | half2) & UINT64CONST(0x8080808080808080)); if (!highbits_set) - return sizeof(uint64); + return 2 * sizeof(uint64); else return 0; } -- 2.22.0