From fac28722eb16cc97c97073c50c969f4d71a33524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Duncan=20P=2E=20N=2E=20Exon=C2=A0Smith?= Date: Thu, 5 Nov 2020 18:23:19 -0500 Subject: [PATCH] Support: Change InMemoryFileSystem::addFileNoOwn to take a MemoryBufferRef, NFC Found this by chance when looking at the InMemoryFileSystem API, seems like an easy cleanup. Differential Revision: https://reviews.llvm.org/D90893 --- include/llvm/Support/VirtualFileSystem.h | 4 +++- lib/Support/VirtualFileSystem.cpp | 6 ++---- unittests/Support/VirtualFileSystemTest.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/llvm/Support/VirtualFileSystem.h b/include/llvm/Support/VirtualFileSystem.h index 055c0e5dd86..714bd7ed305 100644 --- a/include/llvm/Support/VirtualFileSystem.h +++ b/include/llvm/Support/VirtualFileSystem.h @@ -37,6 +37,7 @@ namespace llvm { class MemoryBuffer; +class MemoryBufferRef; class Twine; namespace vfs { @@ -463,7 +464,8 @@ public: /// false if the file or directory already exists in the file system with /// different contents. bool addFileNoOwn(const Twine &Path, time_t ModificationTime, - llvm::MemoryBuffer *Buffer, Optional User = None, + const llvm::MemoryBufferRef &Buffer, + Optional User = None, Optional Group = None, Optional Type = None, Optional Perms = None); diff --git a/lib/Support/VirtualFileSystem.cpp b/lib/Support/VirtualFileSystem.cpp index bbde44c30ca..697383d55d8 100644 --- a/lib/Support/VirtualFileSystem.cpp +++ b/lib/Support/VirtualFileSystem.cpp @@ -792,14 +792,12 @@ bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime, } bool InMemoryFileSystem::addFileNoOwn(const Twine &P, time_t ModificationTime, - llvm::MemoryBuffer *Buffer, + const llvm::MemoryBufferRef &Buffer, Optional User, Optional Group, Optional Type, Optional Perms) { - return addFile(P, ModificationTime, - llvm::MemoryBuffer::getMemBuffer( - Buffer->getBuffer(), Buffer->getBufferIdentifier()), + return addFile(P, ModificationTime, llvm::MemoryBuffer::getMemBuffer(Buffer), std::move(User), std::move(Group), std::move(Type), std::move(Perms)); } diff --git a/unittests/Support/VirtualFileSystemTest.cpp b/unittests/Support/VirtualFileSystemTest.cpp index 64982b9e216..4cc209de1a5 100644 --- a/unittests/Support/VirtualFileSystemTest.cpp +++ b/unittests/Support/VirtualFileSystemTest.cpp @@ -939,7 +939,7 @@ TEST_F(InMemoryFileSystemTest, OverlayFile) { TEST_F(InMemoryFileSystemTest, OverlayFileNoOwn) { auto Buf = MemoryBuffer::getMemBuffer("a"); - FS.addFileNoOwn("/a", 0, Buf.get()); + FS.addFileNoOwn("/a", 0, *Buf); auto Stat = FS.status("/a"); ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString(); ASSERT_EQ("/a", Stat->getName());