@@ -167,7 +167,7 @@ extension _StringGuts {
167
167
result = idx
168
168
} else {
169
169
// TODO(String performance): isASCII check
170
- result = scalarAlignSlow ( idx)
170
+ result = scalarAlignSlow ( idx) . _scalarAligned . _copyEncoding ( from : idx )
171
171
}
172
172
173
173
_internalInvariant ( isOnUnicodeScalarBoundary ( result) ,
@@ -183,15 +183,15 @@ extension _StringGuts {
183
183
184
184
if _slowPath ( idx. transcodedOffset != 0 || idx. _encodedOffset == 0 ) {
185
185
// Transcoded index offsets are already scalar aligned
186
- return String . Index ( _encodedOffset: idx. _encodedOffset) . _scalarAligned
186
+ return String . Index ( _encodedOffset: idx. _encodedOffset)
187
187
}
188
188
if _slowPath ( self . isForeign) {
189
189
// In 5.1 this check was added to foreignScalarAlign, but when this is
190
190
// emitted into a client that then runs against a 5.0 stdlib, it calls
191
191
// a version of foreignScalarAlign that doesn't check for this, which
192
192
// ends up asking CFString for its endIndex'th character, which throws
193
193
// an exception. So we duplicate the check here for back deployment.
194
- guard idx. _encodedOffset != self . count else { return idx. _scalarAligned }
194
+ guard idx. _encodedOffset != self . count else { return idx }
195
195
196
196
let foreignIdx = foreignScalarAlign ( idx)
197
197
_internalInvariant_5_1 ( foreignIdx. _isScalarAligned)
@@ -200,7 +200,7 @@ extension _StringGuts {
200
200
201
201
return String . Index ( _encodedOffset:
202
202
self . withFastUTF8 { _scalarAlign ( $0, idx. _encodedOffset) }
203
- ) . _scalarAligned
203
+ )
204
204
}
205
205
206
206
@inlinable
0 commit comments