Skip to content
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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

PastaPastaPasta
Copy link
Member

This builds on top of #74 to enhance library performance when integrated into other stuff

uint8_t buffer[G1Element::SIZE + 1];
g1_write_bin(buffer, G1Element::SIZE + 1, p, 1);

if (buffer[0] == 0x00) { // infinity
Copy link

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?

Copy link

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 {
Copy link

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{};
Copy link

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

Copy link
Member Author

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

@github-actions
Copy link

'This PR has been flagged as stale due to no activity for over 60
days. It will not be automatically closed, but it has been given
a stale-pr label and should be manually reviewed.'

src/elements.cpp Outdated Show resolved Hide resolved
src/elements.cpp Outdated Show resolved Hide resolved
src/elements.cpp Outdated Show resolved Hide resolved
@PastaPastaPasta
Copy link
Member Author

All done

Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 30aa085

@PastaPastaPasta PastaPastaPasta changed the title Feat/serialize stack feat: serialize on the stack Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants