diff options
| author | Nicholas Wilson <nicholas@nicholaswilson.me.uk> | 2018-03-02 14:48:50 +0000 |
|---|---|---|
| committer | Nicholas Wilson <nicholas@nicholaswilson.me.uk> | 2018-03-02 14:48:50 +0000 |
| commit | f6dbc2edee0f26d49773db3ce6c450d23f572f12 (patch) | |
| tree | 69676f6e64a9100ed1b5ef2e3c734e6cc1d0ca68 /lld/wasm/Writer.cpp | |
| parent | cb81a0c9d9d10a1a7e1882846038c84b321861a3 (diff) | |
| download | bcm5719-llvm-f6dbc2edee0f26d49773db3ce6c450d23f572f12.tar.gz bcm5719-llvm-f6dbc2edee0f26d49773db3ce6c450d23f572f12.zip | |
[WebAssembly] Pass ownership of body to SyntheticFunction. NFC
This avoids the Writer unnecessarily having a member to retain ownership
of the function body.
Differential Revision: https://reviews.llvm.org/D43933
llvm-svn: 326580
Diffstat (limited to 'lld/wasm/Writer.cpp')
| -rw-r--r-- | lld/wasm/Writer.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp index dad2c5fa2df..1b7cde1e91b 100644 --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -17,7 +17,6 @@ #include "WriterUtils.h" #include "lld/Common/ErrorHandler.h" #include "lld/Common/Memory.h" -#include "lld/Common/Strings.h" #include "lld/Common/Threads.h" #include "llvm/ADT/DenseSet.h" #include "llvm/BinaryFormat/Wasm.h" @@ -137,7 +136,6 @@ private: std::vector<OutputSection *> OutputSections; std::unique_ptr<FileOutputBuffer> Buffer; - std::string CtorFunctionBody; std::vector<OutputSegment *> Segments; llvm::SmallDenseMap<StringRef, OutputSegment *> SegmentMap; @@ -859,10 +857,10 @@ void Writer::createCtorFunction() { uint32_t FunctionIndex = NumImportedFunctions + InputFunctions.size(); WasmSym::CallCtors->setOutputIndex(FunctionIndex); - // First write the body bytes to a string. - std::string FunctionBody; + // First write the body's contents to a string. + std::string BodyContent; { - raw_string_ostream OS(FunctionBody); + raw_string_ostream OS(BodyContent); writeUleb128(OS, 0, "num locals"); for (const WasmInitEntry &F : InitFunctions) { writeU8(OS, OPCODE_CALL, "CALL"); @@ -872,14 +870,16 @@ void Writer::createCtorFunction() { } // Once we know the size of the body we can create the final function body - raw_string_ostream OS(CtorFunctionBody); - writeUleb128(OS, FunctionBody.size(), "function size"); - OS.flush(); - CtorFunctionBody += FunctionBody; + std::string FunctionBody; + { + raw_string_ostream OS(FunctionBody); + writeUleb128(OS, BodyContent.size(), "function size"); + OS << BodyContent; + } const WasmSignature *Sig = WasmSym::CallCtors->getFunctionType(); SyntheticFunction *F = make<SyntheticFunction>( - *Sig, toArrayRef(CtorFunctionBody), WasmSym::CallCtors->getName()); + *Sig, std::move(FunctionBody), WasmSym::CallCtors->getName()); F->setOutputIndex(FunctionIndex); F->Live = true; |

