diff --git a/.cargo/config.toml b/.cargo/config.toml index 8af940d2..ebe9d0bc 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,4 +1,5 @@ [build] +rustflags = ["-C", "target-cpu=native"] rustdocflags = ["--cfg", "docsrs"] [env] diff --git a/benchlib/src/lib.rs b/benchlib/src/lib.rs index 9f21ee9b..430d488d 100644 --- a/benchlib/src/lib.rs +++ b/benchlib/src/lib.rs @@ -10,7 +10,7 @@ pub use self::generate::*; macro_rules! bench_dataset { ($ty:ty = $generate:expr) => { #[$crate::divan::bench(min_time = std::time::Duration::from_secs(3))] - pub fn serialize(bencher: $crate::divan::Bencher) { + pub fn ser(bencher: $crate::divan::Bencher) { let data = $generate; let mut bytes = rkyv::util::AlignedVec::<16>::new(); @@ -19,7 +19,7 @@ macro_rules! bench_dataset { buffer.clear(); bytes = $crate::divan::black_box( - rkyv::api::high::to_bytes_in::<_, rkyv::rancor::Panic>( + rkyv::api::high::to_bytes_in::<_, rkyv::rancor::Failure>( $crate::divan::black_box(&data), $crate::divan::black_box(buffer), ) @@ -29,13 +29,13 @@ macro_rules! bench_dataset { } #[$crate::divan::bench(min_time = std::time::Duration::from_secs(3))] - pub fn deserialize(bencher: $crate::divan::Bencher) { + pub fn de(bencher: $crate::divan::Bencher) { let bytes = - rkyv::api::high::to_bytes::(&$generate) + rkyv::api::high::to_bytes::(&$generate) .unwrap(); bencher.bench_local(|| { - rkyv::from_bytes::<$ty, rkyv::rancor::Panic>( + rkyv::from_bytes::<$ty, rkyv::rancor::Failure>( $crate::divan::black_box(&bytes), ) .unwrap() @@ -43,13 +43,13 @@ macro_rules! bench_dataset { } #[$crate::divan::bench(min_time = std::time::Duration::from_secs(3))] - pub fn check_bytes(bencher: $crate::divan::Bencher) { + pub fn check(bencher: $crate::divan::Bencher) { let bytes = - rkyv::api::high::to_bytes::(&$generate) + rkyv::api::high::to_bytes::(&$generate) .unwrap(); bencher.bench_local(|| { - rkyv::access::, rkyv::rancor::Panic>( + rkyv::access::, rkyv::rancor::Failure>( $crate::divan::black_box(&bytes), ) }) diff --git a/rkyv/src/string/repr.rs b/rkyv/src/string/repr.rs index a6c79573..619f5528 100644 --- a/rkyv/src/string/repr.rs +++ b/rkyv/src/string/repr.rs @@ -1,6 +1,11 @@ //! An archived string representation that supports inlining short strings. -use core::{marker::PhantomPinned, mem, ptr, slice, str}; +use core::{ + marker::PhantomPinned, + mem, + ptr::{self, copy_nonoverlapping, write_bytes}, + slice, str, +}; use munge::munge; use rancor::{Panic, ResultExt as _, Source}; @@ -175,12 +180,12 @@ impl ArchivedStringRepr { // valid pointer to bytes because it is a subfield of `out` which the // caller has guaranteed points to a valid location. unsafe { - for i in 0..value.len() { - out_bytes.cast::().add(i).write(value.as_bytes()[i]); - } - for i in value.len()..INLINE_CAPACITY { - out_bytes.cast::().add(i).write(0xff); - } + write_bytes(out_bytes, 0xff, 1); + copy_nonoverlapping( + value.as_bytes().as_ptr(), + out_bytes.cast(), + value.len(), + ); } } diff --git a/rkyv/src/util/alloc/aligned_vec.rs b/rkyv/src/util/alloc/aligned_vec.rs index 80c57f1a..4526023c 100644 --- a/rkyv/src/util/alloc/aligned_vec.rs +++ b/rkyv/src/util/alloc/aligned_vec.rs @@ -564,17 +564,15 @@ impl AlignedVec { /// assert_eq!(vec.as_slice(), &[1, 2, 3, 4]); /// ``` pub fn extend_from_slice(&mut self, other: &[u8]) { - if !other.is_empty() { - self.reserve(other.len()); - unsafe { - core::ptr::copy_nonoverlapping( - other.as_ptr(), - self.as_mut_ptr().add(self.len()), - other.len(), - ); - } - self.len += other.len(); + self.reserve(other.len()); + unsafe { + core::ptr::copy_nonoverlapping( + other.as_ptr(), + self.as_mut_ptr().add(self.len()), + other.len(), + ); } + self.len += other.len(); } /// Removes the last element from a vector and returns it, or `None` if it