[clang] 35918bc - [AST] Sort introspection results without instantiating other data
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 23 08:21:38 PDT 2021
Author: Stephen Kelly
Date: 2021-04-23T16:21:01+01:00
New Revision: 35918bcb6f507cb3d28f80ab4408125ba292400c
URL: https://github.com/llvm/llvm-project/commit/35918bcb6f507cb3d28f80ab4408125ba292400c
DIFF: https://github.com/llvm/llvm-project/commit/35918bcb6f507cb3d28f80ab4408125ba292400c.diff
LOG: [AST] Sort introspection results without instantiating other data
Avoid string allocation in particular, but also avoid attempting to
impose any particular ordering based on formatted results.
Differential Revision: https://reviews.llvm.org/D101054
Added:
Modified:
clang/lib/Tooling/NodeIntrospection.cpp
Removed:
################################################################################
diff --git a/clang/lib/Tooling/NodeIntrospection.cpp b/clang/lib/Tooling/NodeIntrospection.cpp
index 8e2d446c3efec..f01bb1cb9c3ca 100644
--- a/clang/lib/Tooling/NodeIntrospection.cpp
+++ b/clang/lib/Tooling/NodeIntrospection.cpp
@@ -41,6 +41,23 @@ std::string LocationCallFormatterCpp::format(const LocationCall &Call) {
}
namespace internal {
+
+static bool locationCallLessThan(const LocationCall *LHS,
+ const LocationCall *RHS) {
+ if (!LHS && !RHS)
+ return false;
+ if (LHS && !RHS)
+ return true;
+ if (!LHS && RHS)
+ return false;
+ auto compareResult = LHS->name().compare(RHS->name());
+ if (compareResult < 0)
+ return true;
+ if (compareResult > 0)
+ return false;
+ return locationCallLessThan(LHS->on(), RHS->on());
+}
+
bool RangeLessThan::operator()(
std::pair<SourceRange, SharedLocationCall> const &LHS,
std::pair<SourceRange, SharedLocationCall> const &RHS) const {
@@ -54,15 +71,13 @@ bool RangeLessThan::operator()(
else if (LHS.first.getEnd() != RHS.first.getEnd())
return false;
- return LocationCallFormatterCpp::format(*LHS.second) <
- LocationCallFormatterCpp::format(*RHS.second);
+ return locationCallLessThan(LHS.second.get(), RHS.second.get());
}
bool RangeLessThan::operator()(
std::pair<SourceLocation, SharedLocationCall> const &LHS,
std::pair<SourceLocation, SharedLocationCall> const &RHS) const {
if (LHS.first == RHS.first)
- return LocationCallFormatterCpp::format(*LHS.second) <
- LocationCallFormatterCpp::format(*RHS.second);
+ return locationCallLessThan(LHS.second.get(), RHS.second.get());
return LHS.first < RHS.first;
}
} // namespace internal
More information about the cfe-commits
mailing list