[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 02:49:02 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:

hmm, moving to `isOffsetInFileID` makes the performance worse... https://llvm-compile-time-tracker.com/compare.php?from=50c6fcb2a1167b65255d2edce9ef34789b85a7a5&to=1ad5668b6f8e0a54fa258144a765ed3ea0ea8ad0&stat=instructions:u

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


More information about the cfe-commits mailing list