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

Commit

Permalink
Improved performance in lexical write (~5%) (#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Jun 10, 2022
1 parent 4e1dc00 commit d2f5935
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/util/lexical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,19 @@ 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();
buf.set_len(len);

// Safety:
// Omits an unneeded bound check as we just ensured that we reserved `N::FORMATTED_SIZE_DECIMAL`
#[cfg(debug_assertions)]
{
let len = lexical_core::write(n, slice).len();
buf.set_len(len);
}
#[cfg(not(debug_assertions))]
{
let len = lexical_core::write_unchecked(n, slice).len();
buf.set_len(len);
}
}
}

Expand Down

0 comments on commit d2f5935

Please sign in to comment.