Skip to content

Commit

Permalink
small performance improve (dashpay#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
yevgenypi authored Jun 30, 2022
1 parent a90ffba commit 1bdef34
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions go-bindings/threshold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

std::vector<bls::Bytes> toVectorHashes(void** elems, const size_t len) {
std::vector<bls::Bytes> vec;
vec.reserve(len);
for (int i = 0 ; i < len; ++i) {
vec.push_back(
bls::Bytes((uint8_t*)elems[i], HashSize)
Expand Down
2 changes: 2 additions & 0 deletions go-bindings/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
template <class T>
std::vector<T> toBLSVector(void** elems, const size_t len) {
std::vector<T> vec;
vec.reserve(len);
for (int i = 0 ; i < len; ++i) {
T* el = (T*)elems[i];
vec.push_back(*el);
Expand All @@ -30,6 +31,7 @@ std::vector<T> toBLSVector(void** elems, const size_t len) {

std::vector<bls::Bytes> toVectorBytes(void** elems, const size_t len, const std::vector<size_t> vecElemsLens) {
std::vector<bls::Bytes> vec;
vec.reserve(len);
for (int i = 0 ; i < len; ++i) {
uint8_t* elPtr = (uint8_t*)elems[i];
vec.push_back(bls::Bytes(elPtr, vecElemsLens[i]));
Expand Down
1 change: 1 addition & 0 deletions go-bindings/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
template <class T>
std::vector<T> toBLSVector(void** elems, const size_t len) {
std::vector<T> vec;
vec.reserve(len);
for (int i = 0 ; i < len; ++i) {
const T* el = (T*)elems[i];
vec.push_back(*el);
Expand Down
8 changes: 3 additions & 5 deletions src/threshold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ namespace bls {
BLSType Poly::Evaluate(const std::vector<BLSType>& vecIn, const Bytes& id) {
typedef PolyOps<BLSType> Ops;
Ops ops;
std::vector<BLSType> vec = vecIn;
if (vec.size() < 2) {
if (vecIn.size() < 2) {
throw std::length_error("At least 2 coefficients required");
}

Expand All @@ -174,9 +173,8 @@ namespace bls {
bn_read_bin(x, id.begin(), Poly::nIdSize);
ops.ModOrder(x);

BLSType y = vecIn[vec.size() - 1];

for (int i = (int) vec.size() - 2; i >= 0; i--) {
BLSType y = vecIn.back();
for (int i = (int) vecIn.size() - 2; i >= 0; i--) {
y = ops.Mul(y, x);
y = ops.Add(y, vecIn[i]);
}
Expand Down

0 comments on commit 1bdef34

Please sign in to comment.