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

ParserBase: avoid copying around currentLiteral #15741

Merged
merged 1 commit into from
Jan 29, 2025

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.

@@ -198,7 +198,7 @@ void ObjectParser::parseData(Object& _containingObject)
std::string ObjectParser::parseUniqueName(Object const* _containingObject)
{
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
Member

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.

None yet

5 participants