Skip to content

Commit e5f3d2a

Browse files
committed
Remove needess checks in CString::arbitrary()
Use CString::from_vec_unchecked() to get a new CString, as all zero bytes have been removed, improving performance. In debug builds, this function will still check if any zero bytes are present.
1 parent 273d7b6 commit e5f3d2a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,8 @@ impl<'a> Arbitrary<'a> for CString {
885885
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
886886
<Vec<u8> as Arbitrary>::arbitrary(u).map(|mut x| {
887887
x.retain(|&c| c != 0);
888-
Self::new(x).unwrap()
888+
// SAFETY: all zero bytes have been removed
889+
unsafe { Self::from_vec_unchecked(x) }
889890
})
890891
}
891892

0 commit comments

Comments
 (0)