Skip to content

[cpp] Optimise Bytes.ofString utf8#12585

Open
tobil4sk wants to merge 1 commit intoHaxeFoundation:developmentfrom
tobil4sk:fix/cpp-optimize-Bytes.ofString
Open

[cpp] Optimise Bytes.ofString utf8#12585
tobil4sk wants to merge 1 commit intoHaxeFoundation:developmentfrom
tobil4sk:fix/cpp-optimize-Bytes.ofString

Conversation

@tobil4sk
Copy link
Member

@tobil4sk tobil4sk commented Feb 9, 2026

To use the current Utf8.encode method, we have to run getByteCount which iterates through the string to create a buffer which is the right size. However, since Utf8.encode is a public function, it has to validate that the size of the buffer is correct, which means it iterates through the string again.

This new Utf8.encode method without a buffer argument creates its own array and returns it, avoiding the unnecessary check.

This requires the method to be added to hxcpp: HaxeFoundation/hxcpp#1306.

To use the current Utf8.encode method, we have to run getByteCount which
iterates through the string to create a buffer which is the right size.
However, since Utf8.encode is a public function, it has to validate that
the size of the buffer is correct, which means it iterates through the
string again.

This new Utf8.encode method without a buffer argument creates its own
array and returns it, avoiding the unnecessary check.
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.

1 participant