summaryrefslogtreecommitdiffstats
path: root/llvm/include
diff options
context:
space:
mode:
authorAlp Toker <alp@nuanti.com>2014-06-12 04:02:46 +0000
committerAlp Toker <alp@nuanti.com>2014-06-12 04:02:46 +0000
commit3ba7673e3468e3dc2110be6ae1bae88705472c31 (patch)
tree0e8e5ca3cb306d76df30d288ba422c39ce353871 /llvm/include
parentb43a5595145a41a2e1365bffced528036358f1f4 (diff)
downloadbcm5719-llvm-3ba7673e3468e3dc2110be6ae1bae88705472c31.tar.gz
bcm5719-llvm-3ba7673e3468e3dc2110be6ae1bae88705472c31.zip
Avoid redundant allocations in the linker optimisation hint
llvm-svn: 210747
Diffstat (limited to 'llvm/include')
-rw-r--r--llvm/include/llvm/MC/MCLinkerOptimizationHint.h16
1 files changed, 14 insertions, 2 deletions
diff --git a/llvm/include/llvm/MC/MCLinkerOptimizationHint.h b/llvm/include/llvm/MC/MCLinkerOptimizationHint.h
index 3b0d933005d..07016c959fd 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();
}
OpenPOWER on IntegriCloud