@@ -175,17 +175,7 @@ extension String {
175
175
@_inlineable // FIXME(sil-serialize-all)
176
176
public subscript( position: Index ) -> Unicode . Scalar {
177
177
let offset = position. encodedOffset
178
- if _slowPath ( _guts. _isOpaque) {
179
- let opaque = _guts. _asOpaque ( )
180
- return opaque. decodeUnicodeScalar ( startingAt: offset)
181
- } else if _guts. isASCII {
182
- let ascii = _guts. _unmanagedASCIIView
183
- let u = ascii. codeUnit ( atCheckedOffset: offset)
184
- return Unicode . Scalar ( _unchecked: UInt32 ( u) )
185
- } else {
186
- let utf16 = _guts. _unmanagedUTF16View
187
- return utf16. decodeUnicodeScalar ( startingAt: offset)
188
- }
178
+ return _guts. unicodeScalar ( startingAt: offset)
189
179
}
190
180
191
181
/// An iterator over the Unicode scalars that make up a `UnicodeScalarView`
@@ -281,6 +271,34 @@ extension String {
281
271
public typealias UnicodeScalarIndex = UnicodeScalarView . Index
282
272
}
283
273
274
+ extension _StringGuts {
275
+ @_inlineable
276
+ @_versioned
277
+ internal func unicodeScalar( startingAt offset: Int ) -> Unicode . Scalar {
278
+ if _slowPath ( _isOpaque) {
279
+ return _asOpaque ( ) . unicodeScalar ( startingAt: offset)
280
+ }
281
+ if isASCII {
282
+ let u = _unmanagedASCIIView. codeUnit ( atCheckedOffset: offset)
283
+ return Unicode . Scalar ( _unchecked: UInt32 ( u) )
284
+ }
285
+ return _unmanagedUTF16View. unicodeScalar ( startingAt: offset)
286
+ }
287
+
288
+ @_inlineable
289
+ @_versioned
290
+ internal func unicodeScalar( endingAt offset: Int ) -> Unicode . Scalar {
291
+ if _slowPath ( _isOpaque) {
292
+ return _asOpaque ( ) . unicodeScalar ( endingAt: offset)
293
+ }
294
+ if isASCII {
295
+ let u = _unmanagedASCIIView. codeUnit ( atCheckedOffset: offset - 1 )
296
+ return Unicode . Scalar ( _unchecked: UInt32 ( u) )
297
+ }
298
+ return _unmanagedUTF16View. unicodeScalar ( endingAt: offset)
299
+ }
300
+ }
301
+
284
302
extension String . UnicodeScalarView : _SwiftStringView {
285
303
@_inlineable // FIXME(sil-serialize-all)
286
304
@_versioned // FIXME(sil-serialize-all)
0 commit comments