-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: serialize on the stack #75
base: develop
Are you sure you want to change the base?
feat: serialize on the stack #75
Conversation
uint8_t buffer[G1Element::SIZE + 1]; | ||
g1_write_bin(buffer, G1Element::SIZE + 1, p, 1); | ||
|
||
if (buffer[0] == 0x00) { // infinity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation of G1Element::Serialize
and G1Element::SerializeToArray
90% same and basically code-paste...
Can you refactor it to use some util method or call functions from each of other?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one will work fine:
std::vector<uint8_t> G1Element::Serialize(const bool fLegacy) const {
const auto arr = G1Element::SerializeToArray(fLegacy);
return std::vector<uint8_t>{arr.begin(), arr.end()};
}
@@ -405,6 +444,44 @@ std::vector<uint8_t> G2Element::Serialize(const bool fLegacy) const { | |||
return result; | |||
} | |||
|
|||
std::array<uint8_t, G2Element::SIZE> G2Element::SerializeToArray(const bool fLegacy) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code duplication with G2Element::Serialize()
@@ -534,4 +611,11 @@ std::vector<uint8_t> GTElement::Serialize() const | |||
return data; | |||
} | |||
|
|||
std::array<uint8_t, GTElement::SIZE> GTElement::SerializeToArray() const | |||
{ | |||
std::array<uint8_t, GTElement::SIZE> data{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not required {} at the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to initialize data, then let it potentially be uninitialized
'This PR has been flagged as stale due to no activity for over 60 |
8a2086e
to
2efa4f2
Compare
2efa4f2
to
0f3705b
Compare
All done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 30aa085
This builds on top of #74 to enhance library performance when integrated into other stuff