Skip to content

[stdlib] Make some trivial Substring methods inlinable #22616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions stdlib/public/core/Substring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,9 @@ extension Substring: StringProtocol {
return _slice.distance(from: start, to: end)
}

@inlinable
public subscript(i: Index) -> Character {
return _slice[i]
@inline(__always) get { return _slice[i] }
}

public mutating func replaceSubrange<C>(
Expand Down Expand Up @@ -402,12 +403,15 @@ extension Substring.UTF8View : BidirectionalCollection {
_slice._failEarlyRangeCheck(range, bounds: bounds)
}

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

@inlinable
public func formIndex(before i: inout Index) {
_slice.formIndex(before: &i)
}

@inlinable
public subscript(r: Range<Index>) -> Substring.UTF8View {
// FIXME(strings): tests.
_precondition(r.lowerBound >= startIndex && r.upperBound <= endIndex,
Expand Down Expand Up @@ -804,5 +808,3 @@ extension Substring {
return Substring(_slice[r])
}
}