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

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 3 07:27:46 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)
----------------
erichkeane wrote:

Ow!  That is sad.  I guess 1927 says that `isOffsetInFileID` is a `very hot method`, so that tells me that this check succeeds comparatively rarely in THAT function.  Makes me wonder how valuable it is HERE, though I guess with all the work `slow` is doing, it matters...

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


More information about the cfe-commits mailing list