Skip to content

avoid unnecessary copy in openHeader() - detected by upcoming clang-tidy check performance-unnecessary-copy-on-last-use #276

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

Merged
merged 1 commit into from
Nov 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2862,11 +2862,15 @@ static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const

if (systemheader) {
ret = openHeaderIncludePath(f, dui, header);
return ret.empty() ? openHeaderRelative(f, sourcefile, header) : ret;
if (ret.empty())
return openHeaderRelative(f, sourcefile, header);
return ret;
}

ret = openHeaderRelative(f, sourcefile, header);
return ret.empty() ? openHeaderIncludePath(f, dui, header) : ret;
if (ret.empty())
openHeaderIncludePath(f, dui, header);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Missing the return.

Like I pointed out in other PRs we need have tests which use include files (which need to exist on the filesystem).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in #281.

return ret;
}

static std::string getFileName(const std::map<std::string, simplecpp::TokenList *> &filedata, const std::string &sourcefile, const std::string &header, const simplecpp::DUI &dui, bool systemheader)
Expand Down