Skip to content

Commit 4aae824

Browse files
committed
[stdlib] String: Deprecate old bounds checking methods
These weren’t doing the right thing, and all callers have now migrated to the new `_StringGuts.validate*` methods, which combine bounds checks with encoding validation and scalar alignment.
1 parent e821269 commit 4aae824

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

stdlib/public/core/StringRangeReplaceableCollection.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,24 +311,28 @@ extension String: RangeReplaceableCollection {
311311
}
312312

313313
extension String {
314-
@inlinable @inline(__always)
314+
@available(*, deprecated,
315+
message: "Use one of the _StringGuts.validateScalarIndex methods")
316+
@usableFromInline // Used to be inlinable before 5.7
315317
internal func _boundsCheck(_ index: Index) {
316-
_precondition(index._encodedOffset >= 0 && index._encodedOffset < _guts.count,
318+
_precondition(index._encodedOffset < _guts.count,
317319
"String index is out of bounds")
318320
}
319321

320-
@inlinable @inline(__always)
322+
@available(*, deprecated,
323+
message: "Use one of the _StringGuts.validateScalarIndexRange methods")
324+
@usableFromInline // Used to be inlinable before 5.7
321325
internal func _boundsCheck(_ range: Range<Index>) {
322326
_precondition(
323-
range.lowerBound._encodedOffset >= 0 &&
324327
range.upperBound._encodedOffset <= _guts.count,
325328
"String index range is out of bounds")
326329
}
327330

328-
@inlinable @inline(__always)
331+
@available(*, deprecated,
332+
message: "Use one of the _StringGuts.validateScalarIndex methods")
333+
@usableFromInline // Used to be inlinable before 5.7
329334
internal func _boundsCheck(_ range: ClosedRange<Index>) {
330335
_precondition(
331-
range.lowerBound._encodedOffset >= 0 &&
332336
range.upperBound._encodedOffset < _guts.count,
333337
"String index range is out of bounds")
334338
}

0 commit comments

Comments
 (0)