From 410c6e5b48564be41da1267c44aa8234d2365ec9 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 31 May 2018 16:53:56 +0100 Subject: [PATCH] rpc: convert distribution to cumulative after caching This avoids double conversion on a later cache hit --- src/rpc/core_rpc_server.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index e28914d96..418f5b671 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -2132,12 +2132,6 @@ namespace cryptonote if (offset <= req.to_height && req.to_height - offset + 1 < distribution.size()) distribution.resize(req.to_height - offset + 1); } - if (req.cumulative) - { - distribution[0] += base; - for (size_t n = 1; n < distribution.size(); ++n) - distribution[n] += distribution[n-1]; - } if (amount == 0) { @@ -2149,6 +2143,13 @@ namespace cryptonote d.cached = true; } + if (req.cumulative) + { + distribution[0] += base; + for (size_t n = 1; n < distribution.size(); ++n) + distribution[n] += distribution[n-1]; + } + res.distributions.push_back({amount, start_height, std::move(distribution), base}); } }