-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
base: main
Are you sure you want to change the base?
Conversation
Mostly taken from #6756 and discovered by reviewing the code. Still needs to be profiled. |
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
No description provided.