v22-addendum-32-bit-transitions.txt
text/plain
Filename: v22-addendum-32-bit-transitions.txt
Type: text/plain
Part: 0
Message:
Re: speed up verifying UTF-8
diff --git a/src/port/pg_utf8_fallback.c b/src/port/pg_utf8_fallback.c
index 25e3031b48..0505feffc5 100644
--- a/src/port/pg_utf8_fallback.c
+++ b/src/port/pg_utf8_fallback.c
@@ -29,7 +29,7 @@
* With six bits per state, the mask is 63, whose importance is described
* later.
*/
-#define DFA_BITS_PER_STATE 6
+#define DFA_BITS_PER_STATE 5
#define DFA_MASK ((1 << DFA_BITS_PER_STATE) - 1)
@@ -82,19 +82,19 @@
*/
/* Invalid state */
-#define ERR UINT64CONST(0)
+#define ERR 0
/* Begin */
-#define BGN (UINT64CONST(1) * DFA_BITS_PER_STATE)
+#define BGN 11
/* Continuation states */
-#define CS1 (UINT64CONST(2) * DFA_BITS_PER_STATE) /* expect 1 cont. byte */
-#define CS2 (UINT64CONST(3) * DFA_BITS_PER_STATE) /* expect 2 cont. bytes */
-#define CS3 (UINT64CONST(4) * DFA_BITS_PER_STATE) /* expect 3 cont. bytes */
+#define CS1 16 /* expect 1 cont. byte */
+#define CS2 1 /* expect 2 cont. bytes */
+#define CS3 5 /* expect 3 cont. bytes */
/* Partial 3-byte sequence states, expect 1 more cont. byte */
-#define P3A (UINT64CONST(5) * DFA_BITS_PER_STATE) /* leading byte was E0 */
-#define P3B (UINT64CONST(6) * DFA_BITS_PER_STATE) /* leading byte was ED */
+#define P3A 6 /* leading byte was E0 */
+#define P3B 20 /* leading byte was ED */
/* Partial 4-byte sequence states, expect 2 more cont. bytes */
-#define P4A (UINT64CONST(7) * DFA_BITS_PER_STATE) /* leading byte was F0 */
-#define P4B (UINT64CONST(8) * DFA_BITS_PER_STATE) /* leading byte was F4 */
+#define P4A 25 /* leading byte was F0 */
+#define P4B 30 /* leading byte was F4 */
/* Begin and End are the same state */
#define END BGN
@@ -123,7 +123,7 @@
#define L4C (P4B << BGN)
/* map an input byte to its byte category */
-const uint64 ByteCategory[256] =
+const uint32 ByteCategory[256] =
{
/* ASCII */
@@ -181,7 +181,7 @@ const uint64 ByteCategory[256] =
};
static inline void
-utf8_advance(const unsigned char *s, uint64 *state, int len)
+utf8_advance(const unsigned char *s, uint32 *state, int len)
{
/* Note: We deliberately don't check the state within the loop. */
while (len > 0)
@@ -216,7 +216,7 @@ int
pg_validate_utf8_fallback(const unsigned char *s, int len)
{
const int orig_len = len;
- uint64 state = BGN;
+ uint32 state = BGN;
while (len >= STRIDE_LENGTH)
{