Skip to content

Commit 2897daa

Browse files
authored
Merge pull request #22616 from karwa/substring_inline
[stdlib] Make some trivial Substring methods inlinable
2 parents f00cf8a + ab36b51 commit 2897daa

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

stdlib/public/core/Substring.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ extension Substring: StringProtocol {
200200
return _slice.distance(from: start, to: end)
201201
}
202202

203+
@inlinable
203204
public subscript(i: Index) -> Character {
204-
return _slice[i]
205+
@inline(__always) get { return _slice[i] }
205206
}
206207

207208
public mutating func replaceSubrange<C>(
@@ -408,12 +409,15 @@ extension Substring.UTF8View: BidirectionalCollection {
408409
_slice._failEarlyRangeCheck(range, bounds: bounds)
409410
}
410411

412+
@inlinable
411413
public func index(before i: Index) -> Index { return _slice.index(before: i) }
412414

415+
@inlinable
413416
public func formIndex(before i: inout Index) {
414417
_slice.formIndex(before: &i)
415418
}
416419

420+
@inlinable
417421
public subscript(r: Range<Index>) -> Substring.UTF8View {
418422
// FIXME(strings): tests.
419423
_precondition(r.lowerBound >= startIndex && r.upperBound <= endIndex,
@@ -810,5 +814,3 @@ extension Substring {
810814
return Substring(_slice[r])
811815
}
812816
}
813-
814-

0 commit comments

Comments
 (0)