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
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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits