Skip to content

Commit d24ae9d

Browse files
committed
[stdlib] Remove Substring._endIsCharacterAligned
Now that the cached character stride in indices always mean the stride in the full string, we can stop looking at whether a substring has a character-aligned end index.
1 parent 83df814 commit d24ae9d

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

stdlib/public/core/Substring.swift

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,6 @@ extension Substring {
149149
internal var _startIsCharacterAligned: Bool {
150150
startIndex._isCharacterAligned
151151
}
152-
153-
internal var _endIsCharacterAligned: Bool {
154-
endIndex._isCharacterAligned
155-
}
156152
}
157153

158154
extension Substring {
@@ -322,20 +318,16 @@ extension Substring: StringProtocol {
322318
_internalInvariant(priorOffset >= startIndex._encodedOffset)
323319

324320
var r = Index(
325-
encodedOffset: priorOffset, characterStride: priorStride)._scalarAligned
326-
327-
if
328-
// Don't set the `_isCharacterAligned` bit in indices of exotic substrings
329-
// whose startIndex isn't aligned on a grapheme cluster boundary. (Their
330-
// grapheme breaks may not match with those in `base`.)
331-
_startIsCharacterAligned,
332-
// Likewise if this is the last character in a substring ending on a
333-
// partial grapheme cluster.
334-
_endIsCharacterAligned || i < endIndex
335-
{
321+
encodedOffset: priorOffset, characterStride: priorStride)
322+
323+
// Don't set the `_isCharacterAligned` bit in indices of exotic substrings
324+
// whose startIndex isn't aligned on a grapheme cluster boundary. (Their
325+
// grapheme breaks may not match with those in `base`.)
326+
if _startIsCharacterAligned {
336327
r = r._characterAligned
328+
} else {
329+
r = r._scalarAligned
337330
}
338-
339331
return r
340332
}
341333

0 commit comments

Comments
 (0)