Skip to content

Commit c093154

Browse files
committed
S_is_utf8_overlong: Consolidate switch() cases.
These case statement values all follow a particular pattern, which can be made explicit, and then they all have the same value.
1 parent fc7417e commit c093154

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

utf8.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -516,21 +516,14 @@ S_is_utf8_overlong(const U8 * const s, const STRLEN len)
516516
#endif
517517

518518
case 0xF0:
519-
return (len < 2)
520-
? -1
521-
: NATIVE_UTF8_TO_I8(s[1]) < UTF_MIN_CONTINUATION_BYTE + 0x10;
522519
case 0xF8:
523-
return (len < 2)
524-
? -1
525-
: NATIVE_UTF8_TO_I8(s[1]) < UTF_MIN_CONTINUATION_BYTE + 0x08;
526520
case 0xFC:
527-
return (len < 2)
528-
? -1
529-
: NATIVE_UTF8_TO_I8(s[1]) < UTF_MIN_CONTINUATION_BYTE + 0x04;
530521
case 0xFE:
531522
return (len < 2)
532-
? -1
533-
: NATIVE_UTF8_TO_I8(s[1]) < UTF_MIN_CONTINUATION_BYTE + 0x02;
523+
? -1 /* This pattern encapsulates
524+
* F0 => 0x10; F8 => 0x08; FC => 0x04; FF => 0x02 */
525+
: NATIVE_UTF8_TO_I8(s[1]) < UTF_MIN_CONTINUATION_BYTE
526+
+ 0x100 - NATIVE_UTF8_TO_I8(s[0]);
534527
case 0xFF:
535528
return isFF_overlong(s, len);
536529
}

0 commit comments

Comments
 (0)