Skip to content

Commit 241b686

Browse files
committed
Alternative solution to performance regression.
1 parent e31984b commit 241b686

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

lld/MachO/InputFiles.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ std::optional<MemoryBufferRef> macho::readFile(StringRef path) {
217217
if (entry != cachedReads.end())
218218
return entry->second;
219219

220-
ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr =
221-
MemoryBuffer::getFile(path, false, /*RequiresNullTerminator*/ false);
220+
ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr = MemoryBuffer::getFile(path);
222221
if (std::error_code ec = mbOrErr.getError()) {
223222
error("cannot open " + path + ": " + ec.message());
224223
return std::nullopt;

llvm/lib/Object/Archive.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,7 @@ Expected<StringRef> Archive::Child::getBuffer() const {
584584
if (!FullNameOrErr)
585585
return FullNameOrErr.takeError();
586586
const std::string &FullName = *FullNameOrErr;
587-
ErrorOr<std::unique_ptr<MemoryBuffer>> Buf =
588-
MemoryBuffer::getFile(FullName, false, /*RequiresNullTerminator*/ false);
587+
ErrorOr<std::unique_ptr<MemoryBuffer>> Buf = MemoryBuffer::getFile(FullName);
589588
if (std::error_code EC = Buf.getError())
590589
return errorCodeToError(EC);
591590
Parent->ThinBuffers.push_back(std::move(*Buf));

llvm/lib/Support/MemoryBuffer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,9 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
505505
// On at least Linux, and possibly on other systems, mmap may return pages
506506
// from the page cache that are not properly filled with trailing zeroes,
507507
// if some prior user of the page wrote non-zero bytes. Detect this and
508-
// don't use mmap in that case.
509-
if (!RequiresNullTerminator || *Result->getBufferEnd() == '\0')
508+
// don't use mmap in that case (unless it is an object file).
509+
if (!RequiresNullTerminator || *Result->getBufferEnd() == '\0' ||
510+
StringRef(Filename.str()).ends_with(".o"))
510511
return std::move(Result);
511512
}
512513
}

0 commit comments

Comments
 (0)