[llvm] eb4c85e - [llvm-objcopy][NFC][Wasm] Do not use internal buffer while writing into the output.
Alexey Lapshin via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 18 06:07:05 PDT 2021
Author: Alexey Lapshin
Date: 2021-03-18T16:02:45+03:00
New Revision: eb4c85e4501e67f48539bed0e622996ec75d1bd1
URL: https://github.com/llvm/llvm-project/commit/eb4c85e4501e67f48539bed0e622996ec75d1bd1
DIFF: https://github.com/llvm/llvm-project/commit/eb4c85e4501e67f48539bed0e622996ec75d1bd1.diff
LOG: [llvm-objcopy][NFC][Wasm] Do not use internal buffer while writing into the output.
This patch is follow-up for D91028. It implements direct writing into the
output stream for wasm.
Depends on D91028
Differential Revision: https://reviews.llvm.org/D95478
Added:
Modified:
llvm/tools/llvm-objcopy/wasm/Writer.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-objcopy/wasm/Writer.cpp b/llvm/tools/llvm-objcopy/wasm/Writer.cpp
index bce24b859573..2fad9e60c50f 100644
--- a/llvm/tools/llvm-objcopy/wasm/Writer.cpp
+++ b/llvm/tools/llvm-objcopy/wasm/Writer.cpp
@@ -56,29 +56,21 @@ size_t Writer::finalize() {
Error Writer::write() {
size_t TotalSize = finalize();
- std::unique_ptr<WritableMemoryBuffer> Buf =
- WritableMemoryBuffer::getNewMemBuffer(TotalSize);
- if (!Buf)
- return createStringError(errc::not_enough_memory,
- "failed to allocate memory buffer of " +
- Twine::utohexstr(TotalSize) + " bytes");
+ Out.reserveExtraSpace(TotalSize);
// Write the header.
- uint8_t *Ptr = reinterpret_cast<uint8_t *>(Buf->getBufferStart());
- Ptr = std::copy(Obj.Header.Magic.begin(), Obj.Header.Magic.end(), Ptr);
- support::endian::write32le(Ptr, Obj.Header.Version);
- Ptr += sizeof(Obj.Header.Version);
+ Out.write(Obj.Header.Magic.data(), Obj.Header.Magic.size());
+ uint32_t Version;
+ support::endian::write32le(&Version, Obj.Header.Version);
+ Out.write(reinterpret_cast<const char *>(&Version), sizeof(Version));
// Write each section.
for (size_t I = 0, S = SectionHeaders.size(); I < S; ++I) {
- Ptr = std::copy(SectionHeaders[I].begin(), SectionHeaders[I].end(), Ptr);
- ArrayRef<uint8_t> Contents = Obj.Sections[I].Contents;
- Ptr = std::copy(Contents.begin(), Contents.end(), Ptr);
+ Out.write(SectionHeaders[I].data(), SectionHeaders[I].size());
+ Out.write(reinterpret_cast<const char *>(Obj.Sections[I].Contents.data()),
+ Obj.Sections[I].Contents.size());
}
- // TODO: Implement direct writing to the output stream (without intermediate
- // memory buffer Buf).
- Out.write(Buf->getBufferStart(), Buf->getBufferSize());
return Error::success();
}
More information about the llvm-commits
mailing list