Move the resize file feature from mapped_file_region to the only user.

This removes a duplicated stat on every file that llvm-ar looks at.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224138 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2014-12-12 18:13:23 +00:00
parent e1136e38a7
commit 7f4b22e7de
3 changed files with 11 additions and 16 deletions

View File

@@ -654,12 +654,15 @@ TEST_F(FileSystemTest, FileMapping) {
SmallString<64> TempPath;
ASSERT_NO_ERROR(
fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath));
unsigned Size = 4096;
ASSERT_NO_ERROR(fs::resize_file(FileDescriptor, Size));
// Map in temp file and add some content
std::error_code EC;
StringRef Val("hello there");
{
fs::mapped_file_region mfr(FileDescriptor,
fs::mapped_file_region::readwrite, 4096, 0, EC);
fs::mapped_file_region::readwrite, Size, 0, EC);
ASSERT_NO_ERROR(EC);
std::copy(Val.begin(), Val.end(), mfr.data());
// Explicitly add a 0.
@@ -671,14 +674,14 @@ TEST_F(FileSystemTest, FileMapping) {
int FD;
EC = fs::openFileForRead(Twine(TempPath), FD);
ASSERT_NO_ERROR(EC);
fs::mapped_file_region mfr(FD, fs::mapped_file_region::readonly, 0, 0, EC);
fs::mapped_file_region mfr(FD, fs::mapped_file_region::readonly, Size, 0, EC);
ASSERT_NO_ERROR(EC);
// Verify content
EXPECT_EQ(StringRef(mfr.const_data()), Val);
// Unmap temp file
fs::mapped_file_region m(FD, fs::mapped_file_region::readonly, 0, 0, EC);
fs::mapped_file_region m(FD, fs::mapped_file_region::readonly, Size, 0, EC);
ASSERT_NO_ERROR(EC);
ASSERT_EQ(close(FD), 0);
}