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

