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

replaced global emptyString used for const reference results with local instances #7250

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

firewave
Copy link
Collaborator

No description provided.

@@ -4364,7 +4364,8 @@ void CheckOther::overlappingWriteUnion(const Token *tok)

void CheckOther::overlappingWriteFunction(const Token *tok)
{
const std::string &funcname = tok ? tok->str() : emptyString;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like this overlaps with the intent of #7251 (should just use "")

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. That should never be nullptr otherwise the error message would have an empty function name. I will align it to match existing code and integrate with the other PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I assume that code exists for the getErrorMessages() invocation.

@firewave firewave marked this pull request as draft January 24, 2025 14:13
@firewave firewave marked this pull request as ready for review January 25, 2025 18:10
else if (!start->isName())
return emptyString;
else if (!start->isName()) {
static const std::string s_empty_string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Has anyone ever benchmarked this? I wonder if the static object can provide any benefits, since it is returned immediately, and RVO should just construct the object at the target location anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh. I expected this to be a const reference. Will back out.

Has anyone ever benchmarked this?

I have at one point with it being dropped completely and it caused a sizable performance impact. That's why I am doing the removal in steps so it is easier to pinpoint potential regressions. Will profile it again after I get rid of the cold stuff.

The whole thing might only be necessary with older C++ standards (pre-C++17?).

Copy link
Collaborator

Choose a reason for hiding this comment

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

With current GCC, the static version is even slower: https://quick-bench.com/q/goY88i2idDwpvg2VMh9bquG1Tds
No difference with clang. Have not checked older standards.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Interesting. Good to know ahead of doing the profiling for this.

FYI some slightly related things:
llvm/llvm-project#58002
llvm/llvm-project#60165

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