Skip to content

Commit b7c54ac

Browse files
committed
[stdlib] Substring.init: Stop checking things twice
1 parent 1c9c5cc commit b7c54ac

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

stdlib/public/core/Substring.swift

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,6 @@ public struct Substring: Sendable {
9999

100100
@inline(__always)
101101
internal init(_unchecked slice: Slice<String>) {
102-
_internalInvariant(slice.endIndex <= slice._base._guts.endIndex)
103-
_internalInvariant(
104-
slice._base._guts.hasMatchingEncoding(slice.startIndex) &&
105-
slice._base._guts.hasMatchingEncoding(slice.endIndex))
106-
_internalInvariant(
107-
slice.startIndex._isScalarAligned && slice.endIndex._isScalarAligned)
108102
self._slice = slice
109103
_invariantCheck()
110104
}
@@ -167,15 +161,12 @@ extension Substring {
167161
#else
168162
@usableFromInline @inline(never) @_effects(releasenone)
169163
internal func _invariantCheck() {
170-
_internalInvariant(_slice.endIndex <= _wholeGuts.endIndex)
164+
_internalInvariant(endIndex <= _wholeGuts.endIndex)
171165
_internalInvariant(
172-
_wholeGuts.hasMatchingEncoding(_slice.startIndex) &&
173-
_wholeGuts.hasMatchingEncoding(_slice.endIndex))
174-
// Indices are always scalar aligned
166+
_wholeGuts.hasMatchingEncoding(startIndex) &&
167+
_wholeGuts.hasMatchingEncoding(endIndex))
175168
_internalInvariant(
176-
_slice.startIndex == _wholeGuts.scalarAlign(_slice.startIndex) &&
177-
_slice.endIndex == _wholeGuts.scalarAlign(_slice.endIndex))
178-
169+
startIndex._isScalarAligned && endIndex._isScalarAligned)
179170
self.base._invariantCheck()
180171
}
181172
#endif // INTERNAL_CHECKS_ENABLED

0 commit comments

Comments
 (0)