From d682593567d6b47ed12455caf6a50e9f0b6416fc Mon Sep 17 00:00:00 2001 From: John Naylor Date: Sun, 18 Jul 2021 19:31:44 -0400 Subject: [PATCH v18 6/6] Do 8-byte check only if 1-byte check succeeds --- src/common/wchar.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/common/wchar.c b/src/common/wchar.c index 465efd2e0d..a388ff4cba 100644 --- a/src/common/wchar.c +++ b/src/common/wchar.c @@ -1983,20 +1983,21 @@ pg_utf8_verifystr(const unsigned char *s, int len) { int l; - /* fast path for ASCII-subset characters */ - l = check_ascii(s, 8); - if (l) - { - s += l; - len -= l; - continue; - } - /* check if the first byte is both non-zero and doesn't have the high bit set */ if ((signed char) (*s) > 0) { - s++; - len--; + /* fast path for ASCII-subset characters */ + l = check_ascii(s, 8); + if (l) + { + s += l; + len -= l; + } + else + { + s++; + len--; + } continue; } -- 2.31.1