Skip to content
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

Remove an extra string copy while constructing HString #157

Merged
merged 4 commits into from
Apr 9, 2024

Conversation

vinocher-bc
Copy link
Contributor

@vinocher-bc vinocher-bc commented Apr 9, 2024

When an HString is currently constructed, the withCString method makes a copy of the source string for null termination. Then WindowsCreateString created a second copy. An HSTRING doesn't need a null terminated string for construction, so remove withCString and use a single allocation by WindowsPreallocateStringBuffer.

The contents of the source string are copied into the HSTRING_BUFFER created by WindowsPreallocateStringBuffer, and an HSTRING is created from that buffer using WindowsPromoteStringBuffer.

Fixes DEVIN-1237

@vinocher-bc vinocher-bc self-assigned this Apr 9, 2024
@vinocher-bc vinocher-bc requested a review from a team as a code owner April 9, 2024 00:41
CMakePresets.json Outdated Show resolved Hide resolved
swiftwinrt/Resources/Support/HString.swift Outdated Show resolved Hide resolved
swiftwinrt/Resources/Support/HString.swift Outdated Show resolved Hide resolved
@vinocher-bc vinocher-bc force-pushed the vinoo/HStringPreallocate2 branch from 444d232 to 36bcdd3 Compare April 9, 2024 15:22
@vinocher-bc vinocher-bc merged commit 96bd875 into main Apr 9, 2024
1 check passed
@vinocher-bc vinocher-bc deleted the vinoo/HStringPreallocate2 branch April 9, 2024 17:22
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