From 110c570cdd3cd695d4b24d6aae38e7cf4d68507f Mon Sep 17 00:00:00 2001 From: John Naylor Date: Sat, 20 Feb 2021 16:32:21 -0400 Subject: [PATCH v5 3/3] Add an ASCII fast path to non-UTF-8 encoding verification functions. --- src/common/wchar.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/src/common/wchar.c b/src/common/wchar.c index 37c4d4489b..9407d0a79a 100644 --- a/src/common/wchar.c +++ b/src/common/wchar.c @@ -1190,6 +1190,15 @@ pg_eucjp_verifystr(const unsigned char *s, int len) int l; /* fast path for ASCII-subset characters */ + l = check_ascii(s, len); + if (l) + { + s += l; + len -= l; + continue; + } + + /* Found non-ASCII or zero above, so verify a single character. */ if (!IS_HIGHBIT_SET(*s)) { if (*s == '\0') @@ -1248,6 +1257,15 @@ pg_euckr_verifystr(const unsigned char *s, int len) int l; /* fast path for ASCII-subset characters */ + l = check_ascii(s, len); + if (l) + { + s += l; + len -= l; + continue; + } + + /* Found non-ASCII or zero above, so verify a single character. */ if (!IS_HIGHBIT_SET(*s)) { if (*s == '\0') @@ -1331,6 +1349,15 @@ pg_euctw_verifystr(const unsigned char *s, int len) int l; /* fast path for ASCII-subset characters */ + l = check_ascii(s, len); + if (l) + { + s += l; + len -= l; + continue; + } + + /* Found non-ASCII or zero above, so verify a single character. */ if (!IS_HIGHBIT_SET(*s)) { if (*s == '\0') @@ -1384,6 +1411,15 @@ pg_johab_verifystr(const unsigned char *s, int len) int l; /* fast path for ASCII-subset characters */ + l = check_ascii(s, len); + if (l) + { + s += l; + len -= l; + continue; + } + + /* Found non-ASCII or zero above, so verify a single character. */ if (!IS_HIGHBIT_SET(*s)) { if (*s == '\0') @@ -1434,6 +1470,15 @@ pg_mule_verifystr(const unsigned char *s, int len) int l; /* fast path for ASCII-subset characters */ + l = check_ascii(s, len); + if (l) + { + s += l; + len -= l; + continue; + } + + /* Found non-ASCII or zero above, so verify a single character. */ if (!IS_HIGHBIT_SET(*s)) { if (*s == '\0') @@ -1503,6 +1548,15 @@ pg_sjis_verifystr(const unsigned char *s, int len) int l; /* fast path for ASCII-subset characters */ + l = check_ascii(s, len); + if (l) + { + s += l; + len -= l; + continue; + } + + /* Found non-ASCII or zero above, so verify a single character. */ if (!IS_HIGHBIT_SET(*s)) { if (*s == '\0') @@ -1552,6 +1606,15 @@ pg_big5_verifystr(const unsigned char *s, int len) int l; /* fast path for ASCII-subset characters */ + l = check_ascii(s, len); + if (l) + { + s += l; + len -= l; + continue; + } + + /* Found non-ASCII or zero above, so verify a single character. */ if (!IS_HIGHBIT_SET(*s)) { if (*s == '\0') @@ -1601,6 +1664,15 @@ pg_gbk_verifystr(const unsigned char *s, int len) int l; /* fast path for ASCII-subset characters */ + l = check_ascii(s, len); + if (l) + { + s += l; + len -= l; + continue; + } + + /* Found non-ASCII or zero above, so verify a single character. */ if (!IS_HIGHBIT_SET(*s)) { if (*s == '\0') @@ -1650,6 +1722,15 @@ pg_uhc_verifystr(const unsigned char *s, int len) int l; /* fast path for ASCII-subset characters */ + l = check_ascii(s, len); + if (l) + { + s += l; + len -= l; + continue; + } + + /* Found non-ASCII or zero above, so verify a single character. */ if (!IS_HIGHBIT_SET(*s)) { if (*s == '\0') @@ -1710,6 +1791,15 @@ pg_gb18030_verifystr(const unsigned char *s, int len) int l; /* fast path for ASCII-subset characters */ + l = check_ascii(s, len); + if (l) + { + s += l; + len -= l; + continue; + } + + /* Found non-ASCII or zero above, so verify a single character. */ if (!IS_HIGHBIT_SET(*s)) { if (*s == '\0') -- 2.22.0