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

test: use Vec::with_capacity avoid realloc mem #101

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nkysg
Copy link

@nkysg nkysg commented Oct 31, 2024

Pull Request type

test: use Vec::with_capacity avoid realloc mem

Please add the labels corresponding to the type of changes your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build-related changes
  • Documentation content changes
  • Testing
  • Other (please describe):

What is the current behavior?

Resolves: #NA

What is the new behavior?

Does this introduce a breaking change?

Other information

@@ -1081,7 +1081,7 @@ mod test {
// Helper function to generate a vector of bits for testing purposes
fn generate_be_bits(x: &Felt) -> Vec<bool> {
// Initialize an empty vector to store the expected bits
let mut bits = Vec::new();
let mut bits = Vec::with_capacity(x.0.representative().limbs.len() * 8 * 8);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The call to representative is not free at all.
Now there are two of those.

If you want to do this you should

let representative = x.0.representative();

let mut bits = Vec::with_capacity(limbs.len() * 8 * 8);

for limb in representative.limbs {

Copy link
Author

Choose a reason for hiding this comment

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

Done. Thank you.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not what you did.

@nkysg nkysg force-pushed the test_use_Vec_with_capacity branch from af7a414 to a7774fb Compare March 22, 2025 11:40
@nkysg nkysg force-pushed the test_use_Vec_with_capacity branch from a7774fb to 7254cbf Compare March 22, 2025 11:45
@nkysg nkysg requested a review from tdelabro March 22, 2025 11:46
@tdelabro
Copy link
Collaborator

@nkysg run the tests locally before you push


// Iterate over each limb in the representative of x
for limb in x.0.representative().limbs {
for limb in bits.limbs {
Copy link
Collaborator

Choose a reason for hiding this comment

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

won't compile

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.

2 participants