[clang-tools-extra] c96860a - [clang-tidy] Optimize realpath in readability-identifier-naming (#92659)
via cfe-commits
cfe-commits at lists.llvm.org
Tue May 28 13:09:39 PDT 2024
Author: Piotr Zegar
Date: 2024-05-28T22:09:34+02:00
New Revision: c96860aea2c77392bad16f1c4f55014164669de3
URL: https://github.com/llvm/llvm-project/commit/c96860aea2c77392bad16f1c4f55014164669de3
DIFF: https://github.com/llvm/llvm-project/commit/c96860aea2c77392bad16f1c4f55014164669de3.diff
LOG: [clang-tidy] Optimize realpath in readability-identifier-naming (#92659)
- Reduce disk IO usage by adding cache to an realpath introduced by
#81985
Added:
Modified:
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index c3208392df156..828f13805a698 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1414,13 +1414,21 @@ IdentifierNamingCheck::getDiagInfo(const NamingCheckId &ID,
}};
}
+StringRef IdentifierNamingCheck::getRealFileName(StringRef FileName) const {
+ auto Iter = RealFileNameCache.try_emplace(FileName);
+ SmallString<256U> &RealFileName = Iter.first->getValue();
+ if (!Iter.second)
+ return RealFileName;
+ llvm::sys::fs::real_path(FileName, RealFileName);
+ return RealFileName;
+}
+
const IdentifierNamingCheck::FileStyle &
IdentifierNamingCheck::getStyleForFile(StringRef FileName) const {
if (!GetConfigPerFile)
return *MainFileStyle;
- SmallString<128> RealFileName;
- llvm::sys::fs::real_path(FileName, RealFileName);
+ StringRef RealFileName = getRealFileName(FileName);
StringRef Parent = llvm::sys::path::parent_path(RealFileName);
auto Iter = NamingStylesCache.find(Parent);
if (Iter != NamingStylesCache.end())
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
index 27c8e4bc768c4..646ec0eac8dd1 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
@@ -205,6 +205,7 @@ class IdentifierNamingCheck final : public RenamerClangTidyCheck {
const NamingCheckFailure &Failure) const override;
const FileStyle &getStyleForFile(StringRef FileName) const;
+ StringRef getRealFileName(StringRef FileName) const;
/// Find the style kind of a field in an anonymous record.
StyleKind findStyleKindForAnonField(
@@ -222,6 +223,7 @@ class IdentifierNamingCheck final : public RenamerClangTidyCheck {
/// Stores the style options as a vector, indexed by the specified \ref
/// StyleKind, for a given directory.
mutable llvm::StringMap<FileStyle> NamingStylesCache;
+ mutable llvm::StringMap<SmallString<256U>> RealFileNameCache;
FileStyle *MainFileStyle;
ClangTidyContext *Context;
const bool GetConfigPerFile;
More information about the cfe-commits
mailing list