From b2545fbc2a85cd8feca55051626cfc76e30d7f3e Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Mon, 18 Apr 2011 20:54:46 +0000 Subject: malloc elimination: it's a bad idea to use raw_svector_ostream on a small heap-allocated SmallString because it unconditionally forces a malloc. (Revised version of r129688, with the necessary flush() call.) llvm-svn: 129716 --- llvm/lib/MC/MCObjectStreamer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'llvm/lib/MC') diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp index ef22eaaaa49..bd7de5739ad 100644 --- a/llvm/lib/MC/MCObjectStreamer.cpp +++ b/llvm/lib/MC/MCObjectStreamer.cpp @@ -191,8 +191,11 @@ void MCObjectStreamer::EmitInstruction(const MCInst &Inst) { void MCObjectStreamer::EmitInstToFragment(const MCInst &Inst) { MCInstFragment *IF = new MCInstFragment(Inst, getCurrentSectionData()); - raw_svector_ostream VecOS(IF->getCode()); + SmallString<128> Code; + raw_svector_ostream VecOS(Code); getAssembler().getEmitter().EncodeInstruction(Inst, VecOS, IF->getFixups()); + VecOS.flush(); + IF->getCode().append(Code.begin(), Code.end()); } static const MCExpr *BuildSymbolDiff(MCContext &Context, -- cgit v1.2.3