Instead of parsing and compiling the llvm::Regex each time, it's faster to use basic string matching for filename prefix check.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Thanks very much for improving it!
clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h | ||
---|---|---|
45 ↗ | (On Diff #162875) | The logic is a bit subtle here. Agree that using regex is overkill. We still want substring match here, since the Filename does not always start with absl/, so your improvement will change the behavior. I think we should do absl/[absl-libraries] substring match. |
Ah, correct. I totally forgot about the ^string$ for the exact match.
This should not change behavior now. I believe what you propose would make the code easier (there'd only be AbseilLibraries = {"absl/algorithm", ...} and the final return std::any_of(..., [](...) { return Path.find(Library) != StringRef::npos; }); but the performance would be worse (because of the presence of the absl/ prefix in each entry). Would you consider this less efficient but easier-to-follow approach better?
It was my suggestion. I'm fine with the current way as long as we have a clear comment explaining it.
clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h | ||
---|---|---|
43 ↗ | (On Diff #163302) | I think we should have a comment explaining we are matching absl/[absl-libraries] -- the current code is not as straightforward as before. |