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: alloc feature #277

Merged
merged 4 commits into from
Jul 29, 2023
Merged

feat: alloc feature #277

merged 4 commits into from
Jul 29, 2023

Conversation

DaniPopes
Copy link
Contributor

@DaniPopes DaniPopes commented Jul 27, 2023

Motivation

Closes #275
Closes #276

Solution

Feature gate certain functions to "alloc", which is enabled by default through "std".
Unfortunately most of these cannot be alloc-free themselves, because of limitations in the Rust const generics (e.g. generic const exprs).

PR Checklist

  • Added Tests
  • Added Documentation
  • Updated the changelog

let mut cpy = *self;
cpy.limbs.iter_mut().for_each(|limb| limb.reverse_bits());
slice::from_raw_parts(cpy.limbs.as_ptr().cast(), Self::BYTES).to_vec()
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This used to recurse infinitely (to_le_bytes_vec calls as_le_bytes().into_owned() which is this exact expression), make it actually do something on BE targets

src/string.rs Outdated
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just a small refactor / code dedup. No logic changed but it would be nice if we could format numbers in BE without allocating the LE digits and rev iter over them.

@DaniPopes DaniPopes force-pushed the no_alloc branch 3 times, most recently from 9b97797 to 39e2a06 Compare July 27, 2023 21:11
@codecov
Copy link

codecov bot commented Jul 27, 2023

Codecov Report

Patch coverage: 93.98% and project coverage change: +0.16% 🎉

Comparison is base (9c44aa8) 82.57% compared to head (286cfae) 82.73%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #277      +/-   ##
==========================================
+ Coverage   82.57%   82.73%   +0.16%     
==========================================
  Files          52       52              
  Lines        5595     5648      +53     
==========================================
+ Hits         4620     4673      +53     
  Misses        975      975              
Files Changed Coverage Δ
src/add.rs 73.33% <ø> (ø)
src/algorithms/mod.rs 100.00% <ø> (ø)
src/bit_arr.rs 21.35% <ø> (ø)
src/bits.rs 71.71% <ø> (ø)
src/lib.rs 81.05% <ø> (ø)
src/string.rs 79.72% <90.32%> (+0.66%) ⬆️
src/base_convert.rs 93.62% <93.10%> (-0.53%) ⬇️
src/bytes.rs 96.81% <94.11%> (+0.14%) ⬆️
src/modular.rs 99.41% <100.00%> (ø)
src/utils.rs 100.00% <100.00%> (+11.11%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@prestwich prestwich left a comment

Choose a reason for hiding this comment

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

Good. I'm opening issues for further improvements to from_base_le

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.

lib: alloc feature flag base_convert: Do not allocate.
2 participants