mirror of
https://github.com/transmission/transmission
synced 2024-12-24 08:43:27 +00:00
perf: faster Cache::write_contiguous() (#5715)
This commit is contained in:
parent
d2d30c2734
commit
d76d26a580
1 changed files with 5 additions and 4 deletions
|
@ -74,20 +74,21 @@ int Cache::write_contiguous(CIter const begin, CIter const end) const
|
||||||
|
|
||||||
if (end - begin > 1)
|
if (end - begin > 1)
|
||||||
{
|
{
|
||||||
// Yes, there are.
|
// copy blocks into contiguous memory
|
||||||
auto const buflen = std::accumulate(
|
auto const buflen = std::accumulate(
|
||||||
begin,
|
begin,
|
||||||
end,
|
end,
|
||||||
size_t{},
|
size_t{},
|
||||||
[](size_t sum, auto const& block) { return sum + std::size(*block.buf); });
|
[](size_t sum, auto const& block) { return sum + std::size(*block.buf); });
|
||||||
buf.reserve(buflen);
|
buf.resize(buflen);
|
||||||
|
auto* walk = std::data(buf);
|
||||||
for (auto iter = begin; iter != end; ++iter)
|
for (auto iter = begin; iter != end; ++iter)
|
||||||
{
|
{
|
||||||
TR_ASSERT(begin->key.first == iter->key.first);
|
TR_ASSERT(begin->key.first == iter->key.first);
|
||||||
TR_ASSERT(begin->key.second + std::distance(begin, iter) == iter->key.second);
|
TR_ASSERT(begin->key.second + std::distance(begin, iter) == iter->key.second);
|
||||||
buf.insert(std::end(buf), std::begin(*iter->buf), std::end(*iter->buf));
|
walk = std::copy_n(std::data(*iter->buf), std::size(*iter->buf), walk);
|
||||||
}
|
}
|
||||||
TR_ASSERT(std::size(buf) == buflen);
|
TR_ASSERT(std::data(buf) + std::size(buf) == walk);
|
||||||
out = std::data(buf);
|
out = std::data(buf);
|
||||||
outlen = std::size(buf);
|
outlen = std::size(buf);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue