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 {
312312 @inline ( never) // slow-path
313313 internal static func _copying( _ str: Substring ) -> String {
314314 if _fastPath ( str. _wholeGuts. isFastUTF8) {
315- return unsafe str. _wholeGuts . withFastUTF8 ( range: str. _offsetRange) {
315+ var new = unsafe str. _wholeGuts . withFastUTF8 ( range: str. _offsetRange) {
316316 unsafe String. _uncheckedFromUTF8 ( $0)
317317 }
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
318326 }
319327 return unsafe Array( str. utf8) . withUnsafeBufferPointer {
320328 unsafe String. _uncheckedFromUTF8 ( $0)
Original file line number Diff line number Diff line change @@ -185,7 +185,17 @@ extension String {
185185 /// Contiguous strings also benefit from fast-paths and better optimizations.
186186 ///
187187 @_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+ }
189199
190200 /// If this string is not contiguous, make it so. If this mutates the string,
191201 /// it will invalidate any pre-existing indices.
You can’t perform that action at this time.
0 commit comments