mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Removes redundant buffer zeroing in _persistCString func
This commit is contained in:
@@ -73,10 +73,10 @@ internal func _persistCString(_ p: UnsafePointer<CChar>?) -> [CChar]? {
|
||||
guard let cString = p else {
|
||||
return nil
|
||||
}
|
||||
let len = UTF8._nullCodeUnitOffset(in: cString)
|
||||
var result = [CChar](repeating: 0, count: len + 1)
|
||||
for i in 0..<len {
|
||||
result[i] = cString[i]
|
||||
let bytesToCopy = UTF8._nullCodeUnitOffset(in: cString) + 1 // +1 for the terminating NUL
|
||||
let result = [CChar](unsafeUninitializedCapacity: bytesToCopy) { buffer, initializedCount in
|
||||
buffer.baseAddress!.assign(from: cString, count: bytesToCopy)
|
||||
initializedCount = bytesToCopy
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user