Skip to content

Removes redundant buffer zeroing in _persistCString func by using `init(unsafeUninitializedCapacity:initializingWith:) #31121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

valeriyvan
Copy link
Contributor

Removes redundant buffer zeroing in _persistCString func by using `init(unsafeUninitializedCapacity:initializingWith:)

@theblixguy theblixguy requested a review from milseman April 18, 2020 14:27
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use initialize(from:count:) instead of assign when writing into uninitialized memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@valeriyvan valeriyvan requested a review from natecook1000 May 11, 2020 11:10
@valeriyvan
Copy link
Contributor Author

ping

@natecook1000
Copy link
Member

@swift-ci Please smoke test and merge

@swift-ci swift-ci merged commit db0c39f into swiftlang:master Jun 1, 2020
@valeriyvan valeriyvan deleted the RemoveRedundantBufferZeroingNSStringAPI branch February 20, 2023 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants