Skip to content

ValueFlow: avoid various unnecessary copies #7583

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

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

firewave
Copy link
Collaborator

No description provided.

@firewave
Copy link
Collaborator Author

firewave commented Jun 10, 2025

Mostly taken from #6756 and discovered by reviewing the code. Still needs to be profiled.

@firewave firewave marked this pull request as draft June 10, 2025 10:10
@firewave firewave marked this pull request as ready for review June 10, 2025 11:17
@firewave
Copy link
Collaborator Author

Not much in terms of performance which is not surprising since these were found by review and not by profiling.

{
if (!precedes(start, end))
throw InternalError(var->nameToken(), "valueFlowForwardConst: start token does not precede the end token.");
for (Token* tok = start; tok != end; tok = tok->next()) {
if (tok->varId() == var->declarationId()) {
for (const ValueFlow::Value& value : values)
setTokenValue(tok, value, settings);
for (ValueFlow::Value& value : values)
Copy link
Owner

@danmar danmar Jun 12, 2025

Choose a reason for hiding this comment

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

if more then one token has matching varid and this inner loop is executed twice then you will move values that are already moved.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. I was relying on the selfcheck/clang-tidy to catch these things.

@firewave firewave marked this pull request as draft June 12, 2025 13:19
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