File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -312,9 +312,17 @@ extension String {
312
312
@inline ( never) // slow-path
313
313
internal static func _copying( _ str: Substring ) -> String {
314
314
if _fastPath ( str. _wholeGuts. isFastUTF8) {
315
- return unsafe str. _wholeGuts . withFastUTF8 ( range: str. _offsetRange) {
315
+ var new = unsafe str. _wholeGuts . withFastUTF8 ( range: str. _offsetRange) {
316
316
unsafe String. _uncheckedFromUTF8 ( $0)
317
317
}
318
+ #if os(watchOS) && _pointerBitWidth(_32)
319
+ if str. _wholeGuts. isSmall,
320
+ str. _wholeGuts. count > _SmallString. contiguousCapacity ( ) {
321
+ new. reserveCapacity ( _SmallString. capacity + 1 )
322
+ return new
323
+ }
324
+ #endif
325
+ return new
318
326
}
319
327
return unsafe Array( str. utf8) . withUnsafeBufferPointer {
320
328
unsafe String. _uncheckedFromUTF8 ( $0)
Original file line number Diff line number Diff line change @@ -185,7 +185,17 @@ extension String {
185
185
/// Contiguous strings also benefit from fast-paths and better optimizations.
186
186
///
187
187
@_alwaysEmitIntoClient
188
- public var isContiguousUTF8 : Bool { return _guts. isFastUTF8 }
188
+ public var isContiguousUTF8 : Bool {
189
+ if _guts. isFastUTF8 {
190
+ #if os(watchOS) && _pointerBitWidth(_32)
191
+ if _guts. isSmall && _guts. count > _SmallString. contiguousCapacity ( ) {
192
+ return false
193
+ }
194
+ #endif
195
+ return true
196
+ }
197
+ return false
198
+ }
189
199
190
200
/// If this string is not contiguous, make it so. If this mutates the string,
191
201
/// it will invalidate any pre-existing indices.
You can’t perform that action at this time.
0 commit comments