Author: Sam McCall
Date: 2022-01-11T10:18:44+01:00
New Revision: 22ac067b2dce8c90db0bbeecb6ec926f526399df

URL: 
https://github.com/llvm/llvm-project/commit/22ac067b2dce8c90db0bbeecb6ec926f526399df
DIFF: 
https://github.com/llvm/llvm-project/commit/22ac067b2dce8c90db0bbeecb6ec926f526399df.diff

LOG: [clangd] Small optimization in SelectionTree

This seems to be strictly faster in all cases. Before fixing D116978 it
was one of the hot paths, and may become one again.

Added: 
    

Modified: 
    clang-tools-extra/clangd/Selection.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/Selection.cpp 
b/clang-tools-extra/clangd/Selection.cpp
index 7c6b8b3134fe..e15308a19179 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -280,9 +280,12 @@ class SelectionTester {
     SelectionTree::Selection Result = NoTokens;
     while (!ExpandedTokens.empty()) {
       // Take consecutive tokens from the same context together for efficiency.
-      FileID FID = SM.getFileID(ExpandedTokens.front().location());
+      SourceLocation Start = ExpandedTokens.front().location();
+      FileID FID = SM.getFileID(Start);
+      // Comparing SourceLocations against bounds is cheaper than getFileID().
+      SourceLocation Limit = SM.getComposedLoc(FID, SM.getFileIDSize(FID));
       auto Batch = ExpandedTokens.take_while([&](const syntax::Token &T) {
-        return SM.getFileID(T.location()) == FID;
+        return T.location() >= Start && T.location() < Limit;
       });
       assert(!Batch.empty());
       ExpandedTokens = ExpandedTokens.drop_front(Batch.size());


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to