mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 06:51:58 +00:00
Auto merge of #93455 - asquared31415:vec-zero-opts, r=thomcc
Implement internal `IsZero` for Wrapping and Saturating for `Vec` optimizations This implements the `IsZero` trait for the `Wrapping` and `Saturating` types so that users of these types can get the improved performance from the specialization of creating a `Vec` from a single element repeated when it has a zero bit pattern (example `vec![0_i32; 500]`, or after this PR `vec![Wrapping(0_i32); 500]`) CC #60978
This commit is contained in:
commit
289279de11
@ -134,6 +134,7 @@
|
||||
#![feature(ptr_metadata)]
|
||||
#![feature(ptr_sub_ptr)]
|
||||
#![feature(receiver_trait)]
|
||||
#![feature(saturating_int_impl)]
|
||||
#![feature(set_ptr_value)]
|
||||
#![feature(slice_from_ptr_range)]
|
||||
#![feature(slice_group_by)]
|
||||
|
@ -1,3 +1,5 @@
|
||||
use core::num::{Saturating, Wrapping};
|
||||
|
||||
use crate::boxed::Box;
|
||||
|
||||
#[rustc_specialization_trait]
|
||||
@ -144,3 +146,17 @@ impl_is_zero_option_of_nonzero!(
|
||||
NonZeroUsize,
|
||||
NonZeroIsize,
|
||||
);
|
||||
|
||||
unsafe impl<T: IsZero> IsZero for Wrapping<T> {
|
||||
#[inline]
|
||||
fn is_zero(&self) -> bool {
|
||||
self.0.is_zero()
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<T: IsZero> IsZero for Saturating<T> {
|
||||
#[inline]
|
||||
fn is_zero(&self) -> bool {
|
||||
self.0.is_zero()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user