[clang] [clang] SourceManager: Cache offsets for LastFileIDLookup to speed up getFileID (PR #146782)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 3 07:25:55 PDT 2025


================
@@ -1901,9 +1903,8 @@ class SourceManager : public RefCountedBase<SourceManager> {
 
   FileID getFileID(SourceLocation::UIntTy SLocOffset) const {
     // If our one-entry cache covers this offset, just return it.
-    if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
+    if (SLocOffset >= LastLookupStartOffset && SLocOffset < LastLookupEndOffset)
----------------
hokein wrote:

I’ve reverted the changes to `isOffsetInFileID` in this patch to maximize the overall performance gain.

I have some ideas for improving `isOffsetInFileID` and might explore them later -- though it’s not clear whether `isOffsetInFileID` will still be a hot method after this change.



https://github.com/llvm/llvm-project/pull/146782


More information about the cfe-commits mailing list