Skip to content

ParserBase: avoid copying around currentLiteral#15741

Merged
clonker merged 1 commit intodevelopfrom
dont-copy-current-literal-in-parser-base
Jan 29, 2025
Merged

ParserBase: avoid copying around currentLiteral#15741
clonker merged 1 commit intodevelopfrom
dont-copy-current-literal-in-parser-base

Conversation

@clonker
Copy link
Member

@clonker clonker commented Jan 20, 2025

This is something that I randomly stumbled upon when looking at #15712.

The function ParserBase::currentLiteral() is called very frequently, in particular also in a lookup-style (e.g., m_dialect.findBuiltin(currentLiteral())). Currently, each invocation takes a full copy of the string value of whatever the scanner is pointing to.

{
expectToken(Token::StringLiteral, false);
auto const name = currentLiteral();
std::string const name{currentLiteral()};
Copy link
Member Author

Choose a reason for hiding this comment

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

Here storing an explicit copy is required as we advance before returning from the function.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this is an issue, it may be worthwhile to document the lifetime of the string_view in the header (i.e. state that advance invalidates it there)?

@clonker clonker force-pushed the dont-copy-current-literal-in-parser-base branch from 1c760ae to 5389915 Compare January 20, 2025 15:58
@clonker clonker merged commit dcca9d7 into develop Jan 29, 2025
73 checks passed
@clonker clonker deleted the dont-copy-current-literal-in-parser-base branch January 29, 2025 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Comments