diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2019-08-25 01:18:35 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2019-08-25 01:18:35 +0000 |
commit | 894b8d1d85a13fe106411c996e26e571c00dbb78 (patch) | |
tree | 6405380dc3a17fdb6eb43a48a23bd32fe184dc9b /clang/lib/Basic | |
parent | 7da6f432d8bcaeacb87e5d9c2d950d6674a45df9 (diff) | |
download | bcm5719-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
Diffstat (limited to 'clang/lib/Basic')
-rw-r--r-- | clang/lib/Basic/FileManager.cpp | 17 |
1 files changed, 6 insertions, 11 deletions
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 |