Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
omit bound check in lexical write
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jun 10, 2022
1 parent 6919cc3 commit 0506acf
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/util/lexical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ pub fn lexical_to_bytes_mut<N: lexical_core::ToLexical>(n: N, buf: &mut Vec<u8>)
// Length of buf is set as written length afterwards. lexical_core
// creates a valid string, so doesn't need to be checked.
let slice = std::slice::from_raw_parts_mut(buf.as_mut_ptr(), buf.capacity());
let len = lexical_core::write(n, slice).len();

// Safety:
// Omits an unneeded bound check as we just ensured that we reserved `N::FORMATTED_SIZE_DECIMAL`
let len = lexical_core::write_unchecked(n, slice).len();
buf.set_len(len);
}
}
Expand Down

0 comments on commit 0506acf

Please sign in to comment.