-
Notifications
You must be signed in to change notification settings - Fork 48
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
base: main
Are you sure you want to change the base?
Conversation
@@ -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); |
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.
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 {
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.
Done. Thank you.
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.
This is not what you did.
af7a414
to
a7774fb
Compare
a7774fb
to
7254cbf
Compare
@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 { |
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.
won't compile
Pull Request type
test: use Vec::with_capacity avoid realloc mem
Please add the labels corresponding to the type of changes your PR introduces:
What is the current behavior?
Resolves: #NA
What is the new behavior?
Does this introduce a breaking change?
Other information