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

Minor code optimization #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

GermanAizek
Copy link
Contributor

@GermanAizek GermanAizek commented Aug 26, 2024

@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:

@GermanAizek GermanAizek changed the title Reserve Minor code optimization Aug 26, 2024
@GermanAizek
Copy link
Contributor Author

@matyalatte can I continue code refactoring in this branch? you can delete unnecessary changes that you are not satisfied with.

@matyalatte
Copy link
Owner

matyalatte commented Aug 26, 2024

try to compare whether benchmark results on Release will improve with my branch.

Can you run benchmark.yml in your fork when finishing refactoring? I can see the result without fetching your branch.

can I continue code refactoring in this 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 meson test -C build after building.

Ping me again when you've finished refactoring.

Copy link
Owner

@matyalatte matyalatte left a 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/ThreadPool.h Show resolved Hide resolved
include/nest_info.h Outdated Show resolved Hide resolved
Comment on lines 83 to 84
static std::vector<fs::path> FilterExcludedFiles(std::vector<fs::path> filenames,
const std::vector<fs::path>& excludes);
Copy link
Owner

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,

Suggested change
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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix it

src/cleanse.cpp Show resolved Hide resolved
src/file_linter.cpp Outdated Show resolved Hide resolved
src/file_linter.cpp Outdated Show resolved Hide resolved
@GermanAizek
Copy link
Contributor Author

GermanAizek commented Sep 4, 2024

Can you run benchmark.yml in your fork when finishing refactoring? I can see the result without fetching your branch.

@matyalatte how to run benchmark.yml actions on my fork, I have enabled Actions CI in my fork but it is empty.

@aaronliu0130
Copy link

Click on "Benchmark". There then should be a run button somewhere.

@GermanAizek
Copy link
Contributor Author

Ping me again when you've finished refactoring.

@matyalatte https://github.com/GermanAizek/cpplint-cpp/actions/runs/10729927983/job/29757427250

@aaronliu0130
Copy link

You should probably fix the lint errors.

@matyalatte matyalatte added the needs work Requires changes before merging. label Sep 6, 2024
Copy link
Owner

@matyalatte matyalatte left a comment

Choose a reason for hiding this comment

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

@GermanAizek

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,
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
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);
Copy link
Owner

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.

Comment on lines +135 to 138
static bool AddJUnitFailure(const std::string& filename,
size_t linenum,
const std::string& message,
const std::string& category,
Copy link
Owner

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]].

Comment on lines +74 to 75
static bool IsMacroDefinition(const CleansedLines& clean_lines,
const std::string& elided_line, size_t linenum);
Copy link
Owner

Choose a reason for hiding this comment

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

Arguments should be aligned.

Comment on lines +234 to 235
static bool ExpectingFunctionArgs(const CleansedLines& clean_lines,
const std::string& elided_line, size_t linenum);
Copy link
Owner

Choose a reason for hiding this comment

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

Arguments should be aligned.

Comment on lines +32 to 34
[[nodiscard]] bool IsMatched(const std::string& category,
const std::string& file,
size_t linenum) const {
Copy link
Owner

Choose a reason for hiding this comment

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

Arguments should be aligned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs work Requires changes before merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants