mirror of
https://github.com/monero-project/monero.git
synced 2024-11-18 00:37:43 +00:00
Merge pull request #4834
2c7195d8
bulletproofs: avoid std::vector allocations for slice (moneromooo-monero)
This commit is contained in:
commit
3e2abc9eaa
1 changed files with 15 additions and 9 deletions
|
@ -31,6 +31,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <boost/thread/mutex.hpp>
|
#include <boost/thread/mutex.hpp>
|
||||||
#include "misc_log_ex.h"
|
#include "misc_log_ex.h"
|
||||||
|
#include "span.h"
|
||||||
#include "common/perf_timer.h"
|
#include "common/perf_timer.h"
|
||||||
#include "cryptonote_config.h"
|
#include "cryptonote_config.h"
|
||||||
extern "C"
|
extern "C"
|
||||||
|
@ -218,7 +219,7 @@ static rct::key vector_power_sum(const rct::key &x, size_t n)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Given two scalar arrays, construct the inner product */
|
/* Given two scalar arrays, construct the inner product */
|
||||||
static rct::key inner_product(const rct::keyV &a, const rct::keyV &b)
|
static rct::key inner_product(const epee::span<const rct::key> &a, const epee::span<const rct::key> &b)
|
||||||
{
|
{
|
||||||
CHECK_AND_ASSERT_THROW_MES(a.size() == b.size(), "Incompatible sizes of a and b");
|
CHECK_AND_ASSERT_THROW_MES(a.size() == b.size(), "Incompatible sizes of a and b");
|
||||||
rct::key res = rct::zero();
|
rct::key res = rct::zero();
|
||||||
|
@ -229,6 +230,11 @@ static rct::key inner_product(const rct::keyV &a, const rct::keyV &b)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static rct::key inner_product(const rct::keyV &a, const rct::keyV &b)
|
||||||
|
{
|
||||||
|
return inner_product(epee::span<const rct::key>(a.data(), a.size()), epee::span<const rct::key>(b.data(), b.size()));
|
||||||
|
}
|
||||||
|
|
||||||
/* Given two scalar arrays, construct the Hadamard product */
|
/* Given two scalar arrays, construct the Hadamard product */
|
||||||
static rct::keyV hadamard(const rct::keyV &a, const rct::keyV &b)
|
static rct::keyV hadamard(const rct::keyV &a, const rct::keyV &b)
|
||||||
{
|
{
|
||||||
|
@ -294,7 +300,7 @@ static rct::keyV vector_subtract(const rct::keyV &a, const rct::key &b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Multiply a scalar and a vector */
|
/* Multiply a scalar and a vector */
|
||||||
static rct::keyV vector_scalar(const rct::keyV &a, const rct::key &x)
|
static rct::keyV vector_scalar(const epee::span<const rct::key> &a, const rct::key &x)
|
||||||
{
|
{
|
||||||
rct::keyV res(a.size());
|
rct::keyV res(a.size());
|
||||||
for (size_t i = 0; i < a.size(); ++i)
|
for (size_t i = 0; i < a.size(); ++i)
|
||||||
|
@ -304,6 +310,11 @@ static rct::keyV vector_scalar(const rct::keyV &a, const rct::key &x)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static rct::keyV vector_scalar(const rct::keyV &a, const rct::key &x)
|
||||||
|
{
|
||||||
|
return vector_scalar(epee::span<const rct::key>(a.data(), a.size()), x);
|
||||||
|
}
|
||||||
|
|
||||||
/* Create a vector from copies of a single value */
|
/* Create a vector from copies of a single value */
|
||||||
static rct::keyV vector_dup(const rct::key &x, size_t N)
|
static rct::keyV vector_dup(const rct::key &x, size_t N)
|
||||||
{
|
{
|
||||||
|
@ -401,17 +412,12 @@ static rct::keyV invert(rct::keyV x)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compute the slice of a vector */
|
/* Compute the slice of a vector */
|
||||||
static rct::keyV slice(const rct::keyV &a, size_t start, size_t stop)
|
static epee::span<const rct::key> slice(const rct::keyV &a, size_t start, size_t stop)
|
||||||
{
|
{
|
||||||
CHECK_AND_ASSERT_THROW_MES(start < a.size(), "Invalid start index");
|
CHECK_AND_ASSERT_THROW_MES(start < a.size(), "Invalid start index");
|
||||||
CHECK_AND_ASSERT_THROW_MES(stop <= a.size(), "Invalid stop index");
|
CHECK_AND_ASSERT_THROW_MES(stop <= a.size(), "Invalid stop index");
|
||||||
CHECK_AND_ASSERT_THROW_MES(start < stop, "Invalid start/stop indices");
|
CHECK_AND_ASSERT_THROW_MES(start < stop, "Invalid start/stop indices");
|
||||||
rct::keyV res(stop - start);
|
return epee::span<const rct::key>(&a[start], stop - start);
|
||||||
for (size_t i = start; i < stop; ++i)
|
|
||||||
{
|
|
||||||
res[i - start] = a[i];
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static rct::key hash_cache_mash(rct::key &hash_cache, const rct::key &mash0, const rct::key &mash1)
|
static rct::key hash_cache_mash(rct::key &hash_cache, const rct::key &mash0, const rct::key &mash1)
|
||||||
|
|
Loading…
Reference in a new issue