Skip to content

Commit

Permalink
dird: improve write_findex() performance
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arogge committed Jul 5, 2019
1 parent 247ae2d commit 39cfe8d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core/src/dird/bsr.cc
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down

0 comments on commit 39cfe8d

Please sign in to comment.