Skip to content

Commit b39ead1

Browse files
authored
Merge pull request #23863 from milseman/string_cleaning
[gardening] Clean up many String computed vars
2 parents 3f58eb7 + f7cdda2 commit b39ead1

10 files changed

+216
-328
lines changed

stdlib/public/core/SmallString.swift

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ internal struct _SmallString {
3232
@usableFromInline
3333
internal var _storage: RawBitPattern
3434

35-
@inlinable
36-
internal var rawBits: RawBitPattern {
37-
@inline(__always) get { return _storage }
38-
}
35+
@inlinable @inline(__always)
36+
internal var rawBits: RawBitPattern { return _storage }
3937

4038
@inlinable
4139
internal var leadingRawBits: UInt64 {
@@ -76,15 +74,13 @@ internal struct _SmallString {
7674
}
7775

7876
extension _SmallString {
79-
@inlinable
77+
@inlinable @inline(__always)
8078
internal static var capacity: Int {
81-
@inline(__always) get {
8279
#if arch(i386) || arch(arm)
83-
return 10
80+
return 10
8481
#else
85-
return 15
82+
return 15
8683
#endif
87-
}
8884
}
8985

9086
// Get an integer equivalent to the _StringObject.discriminatedObjectRawBits
@@ -95,30 +91,20 @@ extension _SmallString {
9591
return _storage.1.littleEndian
9692
}
9793

98-
@inlinable
99-
internal var capacity: Int {
100-
@inline(__always) get {
101-
return _SmallString.capacity
102-
}
103-
}
94+
@inlinable @inline(__always)
95+
internal var capacity: Int { return _SmallString.capacity }
10496

105-
@inlinable
97+
@inlinable @inline(__always)
10698
internal var count: Int {
107-
@inline(__always) get {
108-
return _StringObject.getSmallCount(fromRaw: rawDiscriminatedObject)
109-
}
99+
return _StringObject.getSmallCount(fromRaw: rawDiscriminatedObject)
110100
}
111101

112-
@inlinable
113-
internal var unusedCapacity: Int {
114-
@inline(__always) get { return capacity &- count }
115-
}
102+
@inlinable @inline(__always)
103+
internal var unusedCapacity: Int { return capacity &- count }
116104

117-
@inlinable
105+
@inlinable @inline(__always)
118106
internal var isASCII: Bool {
119-
@inline(__always) get {
120-
return _StringObject.getSmallIsASCII(fromRaw: rawDiscriminatedObject)
121-
}
107+
return _StringObject.getSmallIsASCII(fromRaw: rawDiscriminatedObject)
122108
}
123109

124110
// Give raw, nul-terminated code units. This is only for limited internal
@@ -170,11 +156,11 @@ extension _SmallString: RandomAccessCollection, MutableCollection {
170156
@usableFromInline
171157
internal typealias SubSequence = _SmallString
172158

173-
@inlinable
174-
internal var startIndex: Int { @inline(__always) get { return 0 } }
159+
@inlinable @inline(__always)
160+
internal var startIndex: Int { return 0 }
175161

176-
@inlinable
177-
internal var endIndex: Int { @inline(__always) get { return count } }
162+
@inlinable @inline(__always)
163+
internal var endIndex: Int { return count }
178164

179165
@inlinable
180166
internal subscript(_ idx: Int) -> UInt8 {
@@ -196,15 +182,12 @@ extension _SmallString: RandomAccessCollection, MutableCollection {
196182
}
197183
}
198184

199-
@inlinable // FIXME(inline-always) was usableFromInline
200-
// testable
185+
@inlinable @inline(__always)
201186
internal subscript(_ bounds: Range<Index>) -> SubSequence {
202-
@inline(__always) get {
203-
// TODO(String performance): In-vector-register operation
204-
return self.withUTF8 { utf8 in
205-
let rebased = UnsafeBufferPointer(rebasing: utf8[bounds])
206-
return _SmallString(rebased)._unsafelyUnwrappedUnchecked
207-
}
187+
// TODO(String performance): In-vector-register operation
188+
return self.withUTF8 { utf8 in
189+
let rebased = UnsafeBufferPointer(rebasing: utf8[bounds])
190+
return _SmallString(rebased)._unsafelyUnwrappedUnchecked
208191
}
209192
}
210193
}

stdlib/public/core/StringCharacterView.swift

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,20 @@ extension String: BidirectionalCollection {
3535
/// The position of the first character in a nonempty string.
3636
///
3737
/// In an empty string, `startIndex` is equal to `endIndex`.
38-
@inlinable
39-
public var startIndex: Index {
40-
@inline(__always) get { return _guts.startIndex }
41-
}
38+
@inlinable @inline(__always)
39+
public var startIndex: Index { return _guts.startIndex }
4240

4341
/// A string's "past the end" position---that is, the position one greater
4442
/// than the last valid subscript argument.
4543
///
4644
/// In an empty string, `endIndex` is equal to `startIndex`.
47-
@inlinable
48-
public var endIndex: Index {
49-
@inline(__always) get { return _guts.endIndex }
50-
}
45+
@inlinable @inline(__always)
46+
public var endIndex: Index { return _guts.endIndex }
5147

5248
/// The number of characters in a string.
49+
@inline(__always)
5350
public var count: Int {
54-
@inline(__always) get {
55-
return distance(from: startIndex, to: endIndex)
56-
}
51+
return distance(from: startIndex, to: endIndex)
5752
}
5853

5954
/// Returns the position immediately after the given index.
@@ -190,16 +185,14 @@ extension String: BidirectionalCollection {
190185
///
191186
/// - Parameter i: A valid index of the string. `i` must be less than the
192187
/// string's end index.
193-
@inlinable
188+
@inlinable @inline(__always)
194189
public subscript(i: Index) -> Character {
195-
@inline(__always) get {
196-
_boundsCheck(i)
190+
_boundsCheck(i)
197191

198-
let i = _guts.scalarAlign(i)
199-
let distance = _characterStride(startingAt: i)
200-
return _guts.errorCorrectedCharacter(
201-
startingAt: i._encodedOffset, endingAt: i._encodedOffset &+ distance)
202-
}
192+
let i = _guts.scalarAlign(i)
193+
let distance = _characterStride(startingAt: i)
194+
return _guts.errorCorrectedCharacter(
195+
startingAt: i._encodedOffset, endingAt: i._encodedOffset &+ distance)
203196
}
204197

205198
@inlinable @inline(__always)

stdlib/public/core/StringGuts.swift

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ struct _StringGuts {
3737

3838
// Raw
3939
extension _StringGuts {
40-
@inlinable
40+
@inlinable @inline(__always)
4141
internal var rawBits: _StringObject.RawBitPattern {
42-
@inline(__always) get { return _object.rawBits }
42+
return _object.rawBits
4343
}
4444
}
4545

@@ -78,34 +78,33 @@ extension _StringGuts {
7878
// Queries
7979
extension _StringGuts {
8080
// The number of code units
81-
@inlinable
82-
internal var count: Int { @inline(__always) get { return _object.count } }
81+
@inlinable @inline(__always)
82+
internal var count: Int { return _object.count }
8383

84-
@inlinable
85-
internal var isEmpty: Bool { @inline(__always) get { return count == 0 } }
84+
@inlinable @inline(__always)
85+
internal var isEmpty: Bool { return count == 0 }
8686

87-
@inlinable
88-
internal var isSmall: Bool {
89-
@inline(__always) get { return _object.isSmall }
90-
}
87+
@inlinable @inline(__always)
88+
internal var isSmall: Bool { return _object.isSmall }
9189

90+
@inline(__always)
9291
internal var isSmallASCII: Bool {
93-
@inline(__always) get { return _object.isSmall && _object.smallIsASCII }
92+
return _object.isSmall && _object.smallIsASCII
9493
}
9594

96-
@inlinable
95+
@inlinable @inline(__always)
9796
internal var asSmall: _SmallString {
98-
@inline(__always) get { return _SmallString(_object) }
97+
return _SmallString(_object)
9998
}
10099

101-
@inlinable
100+
@inlinable @inline(__always)
102101
internal var isASCII: Bool {
103-
@inline(__always) get { return _object.isASCII }
102+
return _object.isASCII
104103
}
105104

106-
@inlinable
105+
@inlinable @inline(__always)
107106
internal var isFastASCII: Bool {
108-
@inline(__always) get { return isFastUTF8 && _object.isASCII }
107+
return isFastUTF8 && _object.isASCII
109108
}
110109

111110
@inline(__always)
@@ -134,9 +133,9 @@ extension _StringGuts {
134133
internal var isFastUTF8: Bool { return _fastPath(_object.providesFastUTF8) }
135134

136135
// A String which does not provide fast access to contiguous UTF-8 code units
137-
@inlinable
136+
@inlinable @inline(__always)
138137
internal var isForeign: Bool {
139-
@inline(__always) get { return _slowPath(_object.isForeign) }
138+
return _slowPath(_object.isForeign)
140139
}
141140

142141
@inlinable @inline(__always)
@@ -259,11 +258,10 @@ extension _StringGuts {
259258
return numWritten
260259
}
261260

261+
@inline(__always)
262262
internal var utf8Count: Int {
263-
@inline(__always) get {
264-
if _fastPath(self.isFastUTF8) { return count }
265-
return String(self).utf8.count
266-
}
263+
if _fastPath(self.isFastUTF8) { return count }
264+
return String(self).utf8.count
267265
}
268266
}
269267

@@ -272,13 +270,13 @@ extension _StringGuts {
272270
@usableFromInline
273271
internal typealias Index = String.Index
274272

275-
@inlinable
273+
@inlinable @inline(__always)
276274
internal var startIndex: String.Index {
277-
@inline(__always) get { return Index(_encodedOffset: 0) }
275+
return Index(_encodedOffset: 0)
278276
}
279-
@inlinable
277+
@inlinable @inline(__always)
280278
internal var endIndex: String.Index {
281-
@inline(__always) get { return Index(_encodedOffset: self.count) }
279+
return Index(_encodedOffset: self.count)
282280
}
283281
}
284282

stdlib/public/core/StringIndex.swift

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,13 @@ extension String {
4949
}
5050

5151
extension String.Index {
52-
@inlinable
53-
internal var orderingValue: UInt64 {
54-
// TODO(String micro-performance): Consider mask instead of shift
55-
@inline(__always) get { return _rawBits &>> 14 }
56-
}
52+
@inlinable @inline(__always)
53+
internal var orderingValue: UInt64 { return _rawBits &>> 14 }
5754

5855
// Whether this is at the canonical "start" position, that is encoded AND
5956
// transcoded offset of 0.
60-
@inlinable
61-
internal var isZeroPosition: Bool {
62-
@inline(__always) get { return orderingValue == 0 }
63-
}
57+
@inlinable @inline(__always)
58+
internal var isZeroPosition: Bool { return orderingValue == 0 }
6459

6560
/// The UTF-16 code unit offset corresponding to this Index
6661
public func utf16Offset<S: StringProtocol>(in s: S) -> Int {
@@ -80,11 +75,9 @@ extension String.Index {
8075
return Int(truncatingIfNeeded: _rawBits &>> 16)
8176
}
8277

83-
@inlinable
78+
@inlinable @inline(__always)
8479
internal var transcodedOffset: Int {
85-
@inline(__always) get {
86-
return Int(truncatingIfNeeded: orderingValue & 0x3)
87-
}
80+
return Int(truncatingIfNeeded: orderingValue & 0x3)
8881
}
8982

9083
@usableFromInline
@@ -164,45 +157,35 @@ extension String.Index {
164157
// Creation helpers, which will make migration easier if we decide to use and
165158
// propagate the reserved bits.
166159
extension String.Index {
167-
@inlinable
160+
@inlinable @inline(__always)
168161
internal var strippingTranscoding: String.Index {
169-
@inline(__always) get {
170-
return String.Index(_encodedOffset: self._encodedOffset)
171-
}
162+
return String.Index(_encodedOffset: self._encodedOffset)
172163
}
173164

174-
@inlinable
165+
@inlinable @inline(__always)
175166
internal var nextEncoded: String.Index {
176-
@inline(__always) get {
177-
_internalInvariant(self.transcodedOffset == 0)
178-
return String.Index(_encodedOffset: self._encodedOffset &+ 1)
179-
}
167+
_internalInvariant(self.transcodedOffset == 0)
168+
return String.Index(_encodedOffset: self._encodedOffset &+ 1)
180169
}
181170

182-
@inlinable
171+
@inlinable @inline(__always)
183172
internal var priorEncoded: String.Index {
184-
@inline(__always) get {
185-
_internalInvariant(self.transcodedOffset == 0)
186-
return String.Index(_encodedOffset: self._encodedOffset &- 1)
187-
}
173+
_internalInvariant(self.transcodedOffset == 0)
174+
return String.Index(_encodedOffset: self._encodedOffset &- 1)
188175
}
189176

190-
@inlinable
177+
@inlinable @inline(__always)
191178
internal var nextTranscoded: String.Index {
192-
@inline(__always) get {
193-
return String.Index(
194-
encodedOffset: self._encodedOffset,
195-
transcodedOffset: self.transcodedOffset &+ 1)
196-
}
179+
return String.Index(
180+
encodedOffset: self._encodedOffset,
181+
transcodedOffset: self.transcodedOffset &+ 1)
197182
}
198183

199-
@inlinable
184+
@inlinable @inline(__always)
200185
internal var priorTranscoded: String.Index {
201-
@inline(__always) get {
202-
return String.Index(
203-
encodedOffset: self._encodedOffset,
204-
transcodedOffset: self.transcodedOffset &- 1)
205-
}
186+
return String.Index(
187+
encodedOffset: self._encodedOffset,
188+
transcodedOffset: self.transcodedOffset &- 1)
206189
}
207190

208191
// Get an index with an encoded offset relative to this one.

0 commit comments

Comments
 (0)