v18-0003-Add-ascii-fast-path-before-resorting-to-DFA.patch
application/octet-stream
Filename: v18-0003-Add-ascii-fast-path-before-resorting-to-DFA.patch
Type: application/octet-stream
Part: 3
Message:
Re: speed up verifying UTF-8
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v18-0003
Subject: Add ascii fast-path before resorting to DFA
| File | + | − |
|---|---|---|
| src/common/wchar.c | 11 | 1 |
From 61f7f10e5af10ff145adca54a0d019968cf77886 Mon Sep 17 00:00:00 2001
From: John Naylor <john.naylor@2ndquadrant.com>
Date: Sun, 18 Jul 2021 18:40:43 -0400
Subject: [PATCH v18 3/6] Add ascii fast-path before resorting to DFA
---
src/common/wchar.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/common/wchar.c b/src/common/wchar.c
index 0454e332cc..4ea352bcf1 100644
--- a/src/common/wchar.c
+++ b/src/common/wchar.c
@@ -1929,7 +1929,6 @@ utf8_advance(const unsigned char *s)
return -1;
Assert((state & DFA_MASK) == END);
- Assert(l <= 4);
return l;
}
@@ -1946,6 +1945,17 @@ pg_utf8_verifystr(const unsigned char *s, int len)
{
int l;
+ /* check if the first byte is both non-zero and doesn't have the high bit set */
+ if ((signed char) (*s) > 0)
+ {
+ s++;
+ len--;
+ continue;
+ }
+
+ /*
+ * Found non-ASCII or zero above, so verify a single character.
+ */
l = utf8_advance(s);
if (l == -1)
goto end;
--
2.31.1