Skip to content

Conversation

@andygrove
Copy link
Member

Summary

Remove an unnecessary String::clone() in maybe_concat_string_literal().

Changes

// Before:
str.push_str(s.clone().as_str());

// After:
str.push_str(s);

Since s is already a &String (from the ref s pattern match), it can be passed directly to push_str() which accepts &str. The deref coercion handles the conversion automatically.

Impact

This removes one heap allocation per concatenated string literal when parsing SQL with adjacent string literals like:

SELECT 'foo' 'bar'  -- Concatenates to 'foobar'

Small change but in the spirit of avoiding unnecessary allocations in the parser hot path.

Test plan

  • All existing tests pass
  • cargo clippy passes

🤖 Generated with Claude Code

Replace `s.clone().as_str()` with just `s` since `s` is already a
`&String` which can be passed directly to `push_str()`.

This removes one String allocation per concatenated string literal
when parsing SQL with adjacent string literals like 'foo' 'bar'.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @andygrove!

@iffyio iffyio added this pull request to the merge queue Jan 23, 2026
Merged via the queue into apache:main with commit 6550ec8 Jan 23, 2026
10 checks passed
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.

2 participants