From 50ebe53353f6870e913f7715d6d4fc5a1f5bedd6 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Mon, 18 Apr 2011 20:54:46 +0000 Subject: [PATCH] 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.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129716 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCObjectStreamer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp index ef22eaaaa49..bd7de5739ad 100644 --- a/lib/MC/MCObjectStreamer.cpp +++ b/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,