mirror of
https://github.com/postgres/postgres.git
synced 2025-07-18 17:42:25 +03:00
Simplify coding style of is_valid_ascii()
Calculate end of input rather than maintaining length, per prior suggestion from Heikki Linnakangas. In passing, use more natural language in a comment. Discussion: https://www.postgresql.org/message-id/b4648cc2-5e9c-c93a-52cc-51e5c658a4f6%40iki.fi
This commit is contained in:
@ -709,13 +709,14 @@ extern WCHAR *pgwin32_message_to_UTF16(const char *str, int len, int *utf16len);
|
|||||||
static inline bool
|
static inline bool
|
||||||
is_valid_ascii(const unsigned char *s, int len)
|
is_valid_ascii(const unsigned char *s, int len)
|
||||||
{
|
{
|
||||||
|
const unsigned char *const s_end = s + len;
|
||||||
uint64 chunk,
|
uint64 chunk,
|
||||||
highbit_cum = UINT64CONST(0),
|
highbit_cum = UINT64CONST(0),
|
||||||
zero_cum = UINT64CONST(0x8080808080808080);
|
zero_cum = UINT64CONST(0x8080808080808080);
|
||||||
|
|
||||||
Assert(len % sizeof(chunk) == 0);
|
Assert(len % sizeof(chunk) == 0);
|
||||||
|
|
||||||
while (len > 0)
|
while (s < s_end)
|
||||||
{
|
{
|
||||||
memcpy(&chunk, s, sizeof(chunk));
|
memcpy(&chunk, s, sizeof(chunk));
|
||||||
|
|
||||||
@ -734,11 +735,10 @@ is_valid_ascii(const unsigned char *s, int len)
|
|||||||
*/
|
*/
|
||||||
zero_cum &= (chunk + UINT64CONST(0x7f7f7f7f7f7f7f7f));
|
zero_cum &= (chunk + UINT64CONST(0x7f7f7f7f7f7f7f7f));
|
||||||
|
|
||||||
/* Capture any set bits in this chunk. */
|
/* Capture all set bits in this chunk. */
|
||||||
highbit_cum |= chunk;
|
highbit_cum |= chunk;
|
||||||
|
|
||||||
s += sizeof(chunk);
|
s += sizeof(chunk);
|
||||||
len -= sizeof(chunk);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if any high bits in the high bit accumulator got set. */
|
/* Check if any high bits in the high bit accumulator got set. */
|
||||||
|
Reference in New Issue
Block a user