[WIP] allow operating on uninitialized data #34
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
background
the core
numtoa_functions (and by extension, the entire library) never reads any data from the output buffer that it has not already written. this should allow us to safely operate on uninitialized slices because the underlying data that we read is always overwritten i.e. we can operate on[MaybeUninit<u8>]instead of[u8]in this PR, i update the code to introduce a new set of API with a set of core functions
numtoa_uninit_e,g,numtoa_uninit_u8&numtoa_uninit_u8_strthat allows operating on uninitialized data. though this does add some extra usage ofunsafe, i think the usage is directly analogous to the existing usage ofcore::str::from_utf8_unchecked& only used when necessary.note that i had to add a bunch of ugly
= MaybeUninit::new()into the codebase becauseMaybeUninit::writedoesn't work in const-contexts, meaning we would have had to otherwise remove compile-time conversion support. i think we can refactor this into a macro in a future PR.tl;dr: this PR provides a new more optimized way to use the classic reused buffer API while also optimizing existing usage of the streamlined API
changes
numtoa_functionsnumtoa_uninit_const functions e.g.numtoa_uninit_i16_strnumtoa_uinit_X_strconst functions e.g.numtoa_uninit_u128_strnumtoa_uinit&numtoa_uinit_strfunctions toNumToAtraitMaybeUninit<u8>instead ofu8assume_slice_initassume_mut_slice_uninitAsciiNumberto useMaybeUninit<u8>AsciiNumber