[clang-tools-extra] 39f779a - [clang-tidy][NFC] Remove redundant string creation for comparison
Nathan James via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 20 14:20:27 PST 2022
Author: Nathan James
Date: 2022-01-20T22:20:10Z
New Revision: 39f779afb35420c51e2c7094b2643a53baed9f59
URL: https://github.com/llvm/llvm-project/commit/39f779afb35420c51e2c7094b2643a53baed9f59
DIFF: https://github.com/llvm/llvm-project/commit/39f779afb35420c51e2c7094b2643a53baed9f59.diff
LOG: [clang-tidy][NFC] Remove redundant string creation for comparison
Added:
Modified:
clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
index fbc1dc6d52a0b..8d620ca3af681 100644
--- a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
@@ -84,15 +84,14 @@ determineIncludeKind(StringRef CanonicalFile, StringRef IncludeFile,
if ((Style == IncludeSorter::IS_Google) ||
(Style == IncludeSorter::IS_Google_ObjC)) {
std::pair<StringRef, StringRef> Parts = CanonicalInclude.split("/public/");
- std::string AltCanonicalInclude =
- Parts.first.str() + "/internal/" + Parts.second.str();
- std::string ProtoCanonicalInclude =
- Parts.first.str() + "/proto/" + Parts.second.str();
-
- // Determine the kind of this inclusion.
- if (CanonicalFile.equals(AltCanonicalInclude) ||
- CanonicalFile.equals(ProtoCanonicalInclude)) {
- return IncludeSorter::IK_MainTUInclude;
+ StringRef FileCopy = CanonicalFile;
+ if (FileCopy.consume_front(Parts.first) &&
+ FileCopy.consume_back(Parts.second)) {
+ // Determine the kind of this inclusion.
+ if (FileCopy.equals("/internal/") ||
+ FileCopy.equals("/proto/")) {
+ return IncludeSorter::IK_MainTUInclude;
+ }
}
}
if (Style == IncludeSorter::IS_Google_ObjC) {
More information about the cfe-commits
mailing list