File tree Expand file tree Collapse file tree 3 files changed +11
-4
lines changed Expand file tree Collapse file tree 3 files changed +11
-4
lines changed Original file line number Diff line number Diff line change 2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
@@ -243,7 +243,9 @@ extension _SmallString {
243
243
fileprivate mutating func withMutableCapacity(
244
244
_ f: ( UnsafeMutableRawBufferPointer ) throws -> Int
245
245
) rethrows {
246
- let len = try withUnsafeMutableBytes ( of: & _storage, f)
246
+ let len = try withUnsafeMutableBytes ( of: & _storage) {
247
+ try f ( . init( start: $0. baseAddress, count: _SmallString. capacity) )
248
+ }
247
249
248
250
if len <= 0 {
249
251
_debugPrecondition ( len == 0 )
Original file line number Diff line number Diff line change 2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
@@ -558,7 +558,9 @@ extension String {
558
558
) throws -> Int
559
559
) rethrows {
560
560
if _fastPath ( capacity <= _SmallString. capacity) {
561
- let smol = try _SmallString ( initializingUTF8With: initializer)
561
+ let smol = try _SmallString ( initializingUTF8With: {
562
+ try initializer ( . init( start: $0. baseAddress, count: capacity) )
563
+ } )
562
564
// Fast case where we fit in a _SmallString and don't need UTF8 validation
563
565
if _fastPath ( smol. isASCII) {
564
566
self = String ( _StringGuts ( smol) )
Original file line number Diff line number Diff line change @@ -70,6 +70,9 @@ if #available(SwiftStdlib 5.3, *) {
70
70
func test( bufferSize: Int , input: [ UInt8 ] , expected: String ) {
71
71
let strs = ( 0 ..< 100 ) . map { _ in
72
72
String ( unsafeUninitializedCapacity: bufferSize) { buffer in
73
+ if #available( SwiftStdlib 5 . 10 , * ) {
74
+ expectEqual ( bufferSize, buffer. count)
75
+ }
73
76
_ = buffer. initialize ( from: input)
74
77
return input. count
75
78
}
You can’t perform that action at this time.
0 commit comments