-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Minor code optimization #7
base: main
Are you sure you want to change the base?
Conversation
@matyalatte can I continue code refactoring in this branch? you can delete unnecessary changes that you are not satisfied with. |
Can you run benchmark.yml in your fork when finishing refactoring? I can see the result without fetching your branch.
Yes, but it seems that your branch is failing unit tests, so it would be better to fix the bug first. You can run the tests with Ping me again when you've finished refactoring. |
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.
I've read the current code. Looks very good to me! I've posted some suggestions, so it would be better to read them before continuing refactoring.
include/options.h
Outdated
static std::vector<fs::path> FilterExcludedFiles(std::vector<fs::path> filenames, | ||
const std::vector<fs::path>& excludes); |
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.
It would be better to align arguments. I mean, insert a linefeed after (
or add more spaces before the second argument.
For example,
static std::vector<fs::path> FilterExcludedFiles(std::vector<fs::path> filenames, | |
const std::vector<fs::path>& excludes); | |
static std::vector<fs::path> FilterExcludedFiles( | |
std::vector<fs::path> filenames, | |
const std::vector<fs::path>& excludes); |
Other lines using [[nodiscard]]
and static
also require similar modifications.
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.
fix it
More info: - https://stackoverflow.com/questions/60784280/string-view-as-a-parameter-of-const-reference - https://stackoverflow.com/questions/57761077/return-const-value-prevent-move-semantics - https://stackoverflow.com/questions/62081977/why-is-there-no-optimization-for-checking-for-empty-string-via-comparison - https://stackoverflow.com/questions/37689228/difference-between-str-clear-and-str
@matyalatte how to run benchmark.yml actions on my fork, I have enabled Actions CI in my fork but it is empty. |
Click on "Benchmark". There then should be a run button somewhere. |
@matyalatte https://github.com/GermanAizek/cpplint-cpp/actions/runs/10729927983/job/29757427250 |
You should probably fix the lint errors. |
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.
https://github.com/GermanAizek/cpplint-cpp/actions/runs/10729927983/job/29757427250
Thanks for the benchmarking. I confirmed that there are no performance issues. I'll merge this PR if some nit picks are fixed.
std::vector<fs::path> FilterExcludedFiles(std::vector<fs::path> filenames, | ||
const std::vector<fs::path>& excludes); | ||
static std::vector<fs::path> FilterExcludedFiles( | ||
std::vector<fs::path> filenames, |
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.
std::vector<fs::path> filenames, | |
std::vector<fs::path> filenames, |
Tab indentations should be removed.
@@ -203,7 +203,7 @@ class NestingState { | |||
} | |||
|
|||
// Check if current position is inside template argument list. | |||
bool InTemplateArgumentList(const CleansedLines& clean_lines, size_t linenum, size_t pos); | |||
static bool InTemplateArgumentList(const CleansedLines& clean_lines, size_t linenum, size_t pos); |
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.
This should be split into two lines to pass the code check.
static bool AddJUnitFailure(const std::string& filename, | ||
size_t linenum, | ||
const std::string& message, | ||
const std::string& category, |
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.
You still need to align arguments for some functions that use static
and [[nodiscard]]
.
static bool IsMacroDefinition(const CleansedLines& clean_lines, | ||
const std::string& elided_line, size_t linenum); |
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.
Arguments should be aligned.
static bool ExpectingFunctionArgs(const CleansedLines& clean_lines, | ||
const std::string& elided_line, size_t linenum); |
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.
Arguments should be aligned.
[[nodiscard]] bool IsMatched(const std::string& category, | ||
const std::string& file, | ||
size_t linenum) const { |
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.
Arguments should be aligned.
@matyalatte thank you so much for this project, I myself dreamed migrating this static linter to C++ or C, you fulfilled my dream. I would like to do my best to contributing.
My code optimization improvements, try to compare whether benchmark results on Release will improve with my branch.
References:
https://stackoverflow.com/questions/57761077/return-const-value-prevent-move-semantics
https://stackoverflow.com/questions/62081977/why-is-there-no-optimization-for-checking-for-empty-string-via-comparison
https://stackoverflow.com/questions/37689228/difference-between-str-clear-and-str
https://stackoverflow.com/questions/60784280/string-view-as-a-parameter-of-const-reference