diff options
author | Alp Toker <alp@nuanti.com> | 2014-06-12 04:02:46 +0000 |
---|---|---|
committer | Alp Toker <alp@nuanti.com> | 2014-06-12 04:02:46 +0000 |
commit | 09d875f8ab1386a921a1cded0fd44246e24b72ea (patch) | |
tree | 3308aff2ad215b2e60fce28db323aa38244285c3 | |
parent | 729fc8facc5cbbe495b8c18c74a99d874e08a307 (diff) | |
download | llvm-09d875f8ab1386a921a1cded0fd44246e24b72ea.tar.gz llvm-09d875f8ab1386a921a1cded0fd44246e24b72ea.tar.bz2 llvm-09d875f8ab1386a921a1cded0fd44246e24b72ea.tar.xz |
Avoid redundant allocations in the linker optimisation hint
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210747 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/MC/MCLinkerOptimizationHint.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/include/llvm/MC/MCLinkerOptimizationHint.h b/include/llvm/MC/MCLinkerOptimizationHint.h index 3b0d933005..07016c959f 100644 --- a/include/llvm/MC/MCLinkerOptimizationHint.h +++ b/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(); } |