summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2019-08-25 01:18:35 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2019-08-25 01:18:35 +0000
commit894b8d1d85a13fe106411c996e26e571c00dbb78 (patch)
tree6405380dc3a17fdb6eb43a48a23bd32fe184dc9b
parent7da6f432d8bcaeacb87e5d9c2d950d6674a45df9 (diff)
downloadbcm5719-llvm-894b8d1d85a13fe106411c996e26e571c00dbb78.tar.gz
bcm5719-llvm-894b8d1d85a13fe106411c996e26e571c00dbb78.zip
FileManager: Factor duplicated code in getBufferForFile, NFC
Incidentally, this also unifies the two versions (removing an unnecessary call to `SmallString::c_str`). llvm-svn: 369861
-rw-r--r--clang/include/clang/Basic/FileManager.h9
-rw-r--r--clang/lib/Basic/FileManager.cpp17
2 files changed, 14 insertions, 12 deletions
diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h
index 0c9a9adedaf..b22afec54e4 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -311,8 +311,15 @@ public:
getBufferForFile(const FileEntry *Entry, bool isVolatile = false,
bool ShouldCloseOpenFile = true);
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
- getBufferForFile(StringRef Filename, bool isVolatile = false);
+ getBufferForFile(StringRef Filename, bool isVolatile = false) {
+ return getBufferForFileImpl(Filename, /*FileSize=*/-1, isVolatile);
+ }
+private:
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+ getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile);
+
+public:
/// Get the 'stat' information for the given \p Path.
///
/// If the path is relative, it will be resolved against the WorkingDir of the
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 3af27564b4c..7138f6677e3 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -447,27 +447,22 @@ FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile,
}
// Otherwise, open the file.
+ return getBufferForFileImpl(Filename, FileSize, isVolatile);
+}
+llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize,
+ bool isVolatile) {
if (FileSystemOpts.WorkingDir.empty())
return FS->getBufferForFile(Filename, FileSize,
/*RequiresNullTerminator=*/true, isVolatile);
- SmallString<128> FilePath(Entry->getName());
+ SmallString<128> FilePath(Filename);
FixupRelativePath(FilePath);
return FS->getBufferForFile(FilePath, FileSize,
/*RequiresNullTerminator=*/true, isVolatile);
}
-llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
-FileManager::getBufferForFile(StringRef Filename, bool isVolatile) {
- if (FileSystemOpts.WorkingDir.empty())
- return FS->getBufferForFile(Filename, -1, true, isVolatile);
-
- SmallString<128> FilePath(Filename);
- FixupRelativePath(FilePath);
- return FS->getBufferForFile(FilePath.c_str(), -1, true, isVolatile);
-}
-
/// getStatValue - Get the 'stat' information for the specified path,
/// using the cache to accelerate it if possible. This returns true
/// if the path points to a virtual file or does not exist, or returns
OpenPOWER on IntegriCloud