[PATCH] D34985: Do not read the file to determine its name.

Vassil Vassilev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 4 07:57:15 PDT 2017


v.g.vassilev created this revision.

Patch by Axel Naumann!


Repository:
  rL LLVM

https://reviews.llvm.org/D34985

Files:
  lib/Basic/SourceManager.cpp


Index: lib/Basic/SourceManager.cpp
===================================================================
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -1474,7 +1474,15 @@
                                        bool *Invalid) const {
   if (isInvalid(Loc, Invalid)) return "<invalid loc>";
 
-  return getBuffer(getFileID(Loc), Invalid)->getBufferIdentifier();
+  // Try to get the name without reading the buffer.
+  FileID FID = getFileID(Loc);
+  const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, Invalid);
+  if (!Invalid && Entry.isFile()) {
+    if (const FileEntry* FE = Entry.getFile().getContentCache()->ContentsEntry)
+      return FE->getName();
+  }
+
+  return getBuffer(FID, Invalid)->getBufferIdentifier();
 }
 
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34985.105177.patch
Type: text/x-patch
Size: 749 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170704/fca3b0a0/attachment-0001.bin>


More information about the cfe-commits mailing list