[PATCH] D101054: [AST] Sort introspection results without instantiating other data

Stephen Kelly via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 22 05:24:09 PDT 2021


steveire created this revision.
steveire added a reviewer: njames93.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Avoid string allocation in particular, but also avoid attempting to
impose any particular ordering based on formatted results.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101054

Files:
  clang/lib/Tooling/NodeIntrospection.cpp


Index: clang/lib/Tooling/NodeIntrospection.cpp
===================================================================
--- clang/lib/Tooling/NodeIntrospection.cpp
+++ clang/lib/Tooling/NodeIntrospection.cpp
@@ -41,6 +41,23 @@
 }
 
 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 @@
   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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101054.339582.patch
Type: text/x-patch
Size: 1584 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210422/9a0ea16f/attachment.bin>


More information about the cfe-commits mailing list