From 08489b5900efbf93060fa3a44578a487fec501d6 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 17 Dec 2017 03:15:18 +0100 Subject: [PATCH] Library: avoid spurious copy in string-join surprise: the standard for-Loop causes a copy of the iterator. From a logical POV this is correct, since the iterator is named, it can not just be moved into the loop construct and be consumed. Thus: write a plain old-fashioned for loop and consume the damn thing. So the top-level call into util::join(&&) decides, if we copy or consume --- src/lib/format-util.hpp | 4 ++-- wiki/thinkPad.ichthyo.mm | 46 +++++++++++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/lib/format-util.hpp b/src/lib/format-util.hpp index 08700b8f6..964955ac9 100644 --- a/src/lib/format-util.hpp +++ b/src/lib/format-util.hpp @@ -197,8 +197,8 @@ namespace util { if (!strings) return ""; std::ostringstream buffer; - for (string const& elm : strings) - buffer << elm << delim; + for ( ; strings; ++strings) + buffer << *strings << delim; // chop off last delimiter size_t len = buffer.str().length(); diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 51a2745f8..9fc97ee18 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -7230,18 +7230,40 @@ - - + + - + - - + + + + + + + + + + + +

+ man kann move(iter) verwenden, +

+

+ wenn man konsumieren möchte +

+ + +
+
+ + +
- - + + @@ -7261,17 +7283,17 @@ - + - - + + - - + +