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

perf: Use Cow for value in MergedCSTNode #64

Merged
merged 3 commits into from
Jul 27, 2024
Merged

perf: Use Cow for value in MergedCSTNode #64

merged 3 commits into from
Jul 27, 2024

Conversation

jpedroh
Copy link
Owner

@jpedroh jpedroh commented Jul 27, 2024

In most scenarios, we don't need to create a new String when merging the values of two CSTNodes. More often than not, we simply pick the value from either the left or right node, or, ideally, the values of both nodes are equal to the base. Consequently, creating owned Strings is uncommon, and it would be more efficient to return a reference to the value of one of the CSTNodes.

To accommodate this use case, this PR updates the MergedCSTNode to use Cow<str> instead of String. This change eliminates unnecessary to_string calls, potentially leading to performance improvements in some scenarios.

Copy link

codesandbox bot commented Jul 27, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@jpedroh jpedroh merged commit c495920 into main Jul 27, 2024
7 checks passed
@jpedroh jpedroh deleted the perf-use-cow branch July 27, 2024 03:15
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