[gardening] Clean up many String computed vars

This commit is contained in:
Michael Ilseman
2019-04-08 11:08:43 -07:00
parent 5150981150
commit f7cdda2720
10 changed files with 218 additions and 330 deletions

View File

@@ -35,25 +35,20 @@ extension String: BidirectionalCollection {
/// The position of the first character in a nonempty string.
///
/// In an empty string, `startIndex` is equal to `endIndex`.
@inlinable
public var startIndex: Index {
@inline(__always) get { return _guts.startIndex }
}
@inlinable @inline(__always)
public var startIndex: Index { return _guts.startIndex }
/// A string's "past the end" position---that is, the position one greater
/// than the last valid subscript argument.
///
/// In an empty string, `endIndex` is equal to `startIndex`.
@inlinable
public var endIndex: Index {
@inline(__always) get { return _guts.endIndex }
}
@inlinable @inline(__always)
public var endIndex: Index { return _guts.endIndex }
/// The number of characters in a string.
@inline(__always)
public var count: Int {
@inline(__always) get {
return distance(from: startIndex, to: endIndex)
}
return distance(from: startIndex, to: endIndex)
}
/// Returns the position immediately after the given index.
@@ -190,16 +185,14 @@ extension String: BidirectionalCollection {
///
/// - Parameter i: A valid index of the string. `i` must be less than the
/// string's end index.
@inlinable
@inlinable @inline(__always)
public subscript(i: Index) -> Character {
@inline(__always) get {
_boundsCheck(i)
_boundsCheck(i)
let i = _guts.scalarAlign(i)
let distance = _characterStride(startingAt: i)
return _guts.errorCorrectedCharacter(
startingAt: i._encodedOffset, endingAt: i._encodedOffset &+ distance)
}
let i = _guts.scalarAlign(i)
let distance = _characterStride(startingAt: i)
return _guts.errorCorrectedCharacter(
startingAt: i._encodedOffset, endingAt: i._encodedOffset &+ distance)
}
@inlinable @inline(__always)