From 3ba7673e3468e3dc2110be6ae1bae88705472c31 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Thu, 12 Jun 2014 04:02:46 +0000 Subject: [PATCH] Avoid redundant allocations in the linker optimisation hint llvm-svn: 210747 --- llvm/include/llvm/MC/MCLinkerOptimizationHint.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/MC/MCLinkerOptimizationHint.h b/llvm/include/llvm/MC/MCLinkerOptimizationHint.h index 3b0d933..07016c9 100644 --- a/llvm/include/llvm/MC/MCLinkerOptimizationHint.h +++ b/llvm/include/llvm/MC/MCLinkerOptimizationHint.h @@ -96,6 +96,19 @@ static inline int MCLOHIdToNbArgs(MCLOHType Kind) { return -1; } +namespace { +class raw_counting_ostream : public raw_ostream { + uint64_t Count = 0; + + void write_impl(const char *, size_t size) override { Count += size; } + + uint64_t current_pos() const override { return Count; } + +public: + ~raw_counting_ostream() { flush(); } +}; +} + /// Store Linker Optimization Hint information (LOH). class MCLOHDirective { MCLOHType Kind; @@ -132,8 +145,7 @@ public: /// the given @p Layout. uint64_t getEmitSize(const MachObjectWriter &ObjWriter, const MCAsmLayout &Layout) const { - std::string Buffer; - raw_string_ostream OutStream(Buffer); + raw_counting_ostream OutStream; Emit_impl(OutStream, ObjWriter, Layout); return OutStream.tell(); } -- 2.7.4