From 39cfe8ddce847ba7cfc42307b5da60e5b2eb9082 Mon Sep 17 00:00:00 2001 From: Andreas Rogge Date: Wed, 3 Jul 2019 10:21:04 +0200 Subject: [PATCH] dird: improve write_findex() performance Previously write_findex() used Bsnprintf() in each loop iteration. This patch now uses std::string and only appends the whole text to the buffer after the loop has finished. --- core/src/dird/bsr.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/dird/bsr.cc b/core/src/dird/bsr.cc index 8f0a0504919..9b351f9e167 100644 --- a/core/src/dird/bsr.cc +++ b/core/src/dird/bsr.cc @@ -157,7 +157,8 @@ uint32_t write_findex(RestoreBootstrapRecordFileIndex* fi, int32_t LastIndex, PoolMem* buffer) { - uint32_t count = 0; + auto count = uint32_t{0}; + auto bsrItems = std::string{}; for (auto& range : fi->getRanges()) { auto first = std::get<0>(range); @@ -169,14 +170,16 @@ uint32_t write_findex(RestoreBootstrapRecordFileIndex* fi, last = std::min(last, LastIndex); if (first == last) { - PrintBsrItem(buffer, "FileIndex=%d\n", first); + bsrItems += "FileIndex=" + std::to_string(first) + "\n"; count++; } else { - PrintBsrItem(buffer, "FileIndex=%d-%d\n", first, last); + bsrItems += "FileIndex=" + std::to_string(first) + "-" + + std::to_string(last) + "\n"; count += last - first + 1; } } } + buffer->strcat(bsrItems.c_str()); return count; }