Skip to content

Commit d1ac870

Browse files
committed
[Parse] Remove duplicate condition check
1 parent 1269b97 commit d1ac870

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/Parse/Lexer.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,21 @@ uint32_t swift::validateUTF8CharacterAndAdvance(const char *&Ptr,
117117
if (CurByte < 0x80)
118118
return CurByte;
119119

120-
// Read the number of high bits set, which indicates the number of bytes in
121-
// the character.
122-
unsigned EncodedBytes = CLO8(CurByte);
123-
124-
// If this is 0b10XXXXXX, then it is a continuation character.
125-
if (EncodedBytes == 1 ||
126-
!isStartOfUTF8Character(CurByte)) {
120+
// If this is not the start of a UTF8 character,
121+
// then it is either a continuation byte or an invalid UTF8 code point.
122+
if (!isStartOfUTF8Character(CurByte)) {
127123
// Skip until we get the start of another character. This is guaranteed to
128124
// at least stop at the nul at the end of the buffer.
129125
while (Ptr < End && !isStartOfUTF8Character(*Ptr))
130126
++Ptr;
131127
return ~0U;
132128
}
133129

130+
// Read the number of high bits set, which indicates the number of bytes in
131+
// the character.
132+
unsigned EncodedBytes = CLO8(CurByte);
133+
assert((EncodedBytes >= 2 && EncodedBytes <= 4));
134+
134135
// Drop the high bits indicating the # bytes of the result.
135136
unsigned CharValue = (unsigned char)(CurByte << EncodedBytes) >> EncodedBytes;
136137

0 commit comments

Comments
 (0)