@@ -201,14 +201,9 @@ extension String.UTF16View: BidirectionalCollection {
201
201
return _foreignIndex ( i, offsetBy: n)
202
202
}
203
203
204
- if n. magnitude <= _StringBreadcrumbs. breadcrumbStride {
204
+ if n. magnitude <= _StringBreadcrumbs. breadcrumbStride, !_guts . isASCII {
205
205
// Do not use breadcrumbs if directly computing the result is expected to
206
206
// be cheaper.
207
- if _guts. isASCII {
208
- return Index (
209
- _encodedOffset: i. _encodedOffset + n
210
- ) . _scalarAligned. _encodingIndependent
211
- }
212
207
return _index ( i, offsetBy: n) . _knownUTF8
213
208
}
214
209
@@ -230,14 +225,9 @@ extension String.UTF16View: BidirectionalCollection {
230
225
return _foreignIndex ( i, offsetBy: n, limitedBy: limit)
231
226
}
232
227
233
- if n. magnitude <= _StringBreadcrumbs. breadcrumbStride {
228
+ if n. magnitude <= _StringBreadcrumbs. breadcrumbStride, !_guts . isASCII {
234
229
// Do not use breadcrumbs if directly computing the result is expected to
235
230
// be cheaper.
236
- if _guts. isASCII {
237
- return ( 0 ..< _guts. count) . index (
238
- i. _encodedOffset, offsetBy: n, limitedBy: limit. _encodedOffset
239
- ) . map { Index ( _encodedOffset: $0) . _scalarAligned. _encodingIndependent }
240
- }
241
231
return _index ( i, offsetBy: n, limitedBy: limit) ? . _knownUTF8
242
232
}
243
233
@@ -278,15 +268,15 @@ extension String.UTF16View: BidirectionalCollection {
278
268
}
279
269
280
270
let utf8Distance = end. _encodedOffset - start. _encodedOffset
281
- if utf8Distance. magnitude <= _StringBreadcrumbs. breadcrumbStride {
271
+ if
272
+ utf8Distance. magnitude <= _StringBreadcrumbs. breadcrumbStride,
273
+ !_guts. isASCII
274
+ {
282
275
// Do not use breadcrumbs if directly computing the result is expected to
283
276
// be cheaper. The conservative threshold above assumes that each UTF-16
284
277
// code unit will map to a single UTF-8 code unit, i.e., the worst
285
278
// possible (a.k.a. most compact) case with all ASCII scalars.
286
279
// FIXME: Figure out if a more optimistic threshold would work better.
287
- if _guts. isASCII {
288
- return end. _encodedOffset - start. _encodedOffset
289
- }
290
280
return _utf16Distance ( from: start, to: end)
291
281
}
292
282
let lower = _nativeGetOffset ( for: start)
0 commit comments