Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6b41a15

Browse files
committed
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
1 parent 82593b9 commit 6b41a15

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/include/mb/pg_wchar.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,13 +709,14 @@ extern WCHAR *pgwin32_message_to_UTF16(const char *str, int len, int *utf16len);
709709
static inline bool
710710
is_valid_ascii(const unsigned char *s, int len)
711711
{
712+
const unsigned char *const s_end = s + len;
712713
uint64 chunk,
713714
highbit_cum = UINT64CONST(0),
714715
zero_cum = UINT64CONST(0x8080808080808080);
715716

716717
Assert(len % sizeof(chunk) == 0);
717718

718-
while (len > 0)
719+
while (s < s_end)
719720
{
720721
memcpy(&chunk, s, sizeof(chunk));
721722

@@ -734,11 +735,10 @@ is_valid_ascii(const unsigned char *s, int len)
734735
*/
735736
zero_cum &= (chunk + UINT64CONST(0x7f7f7f7f7f7f7f7f));
736737

737-
/* Capture any set bits in this chunk. */
738+
/* Capture all set bits in this chunk. */
738739
highbit_cum |= chunk;
739740

740741
s += sizeof(chunk);
741-
len -= sizeof(chunk);
742742
}
743743

744744
/* Check if any high bits in the high bit accumulator got set. */

0 commit comments

Comments
 (0)