Skip to content

Commit 44cccba

Browse files
committed
[stdlib] Change dynamic check to sanity check.
Double-checking for CR-LF is redundant in _internalExtraCheckGraphemeBreakBetween. Add in a sanity check and omit the overly conservative CR check.
1 parent 6ee5745 commit 44cccba

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

stdlib/public/core/StringCharacterView.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ extension String.CharacterView : BidirectionalCollection {
297297
internal static func _internalExtraCheckGraphemeBreakBetween(
298298
_ lhs: UInt16, _ rhs: UInt16
299299
) -> Bool {
300+
_sanityCheck(
301+
lhs != _CR || rhs != _LF,
302+
"CR-LF special case handled by _quickCheckGraphemeBreakBetween")
303+
300304
// Whether the given scalar, when it appears paired with another scalar
301305
// satisfying this property, has a grapheme break between it and the other
302306
// scalar.
@@ -316,10 +320,10 @@ extension String.CharacterView : BidirectionalCollection {
316320
// Repeat sub-300 check, this is beneficial for common cases of Latin
317321
// characters embedded within non-Latin script (e.g. newlines, spaces,
318322
// proper nouns and/or jargon, punctuation).
319-
case 0x0000...0x02ff:
320-
// Conservatively exclude CR, though this might not be necessary from
321-
// previous checks.
322-
return x != _CR
323+
//
324+
// NOTE: CR-LF special case has already been checked.
325+
case 0x0000...0x02ff: return true
326+
323327
// TODO: general punctuation
324328

325329
// Non-combining kana:

0 commit comments

Comments
 (0)