Add inlining.

This commit is contained in:
Camille GILLOT 2021-03-11 11:49:23 +01:00
parent 17a07d71bf
commit 84bf599bac
3 changed files with 16 additions and 0 deletions

View File

@ -35,6 +35,7 @@ impl StableHasher {
StableHasher { state: SipHasher128::new_with_keys(0, 0) } StableHasher { state: SipHasher128::new_with_keys(0, 0) }
} }
#[inline]
pub fn finish<W: StableHasherResult>(self) -> W { pub fn finish<W: StableHasherResult>(self) -> W {
W::finish(self) W::finish(self)
} }

View File

@ -74,6 +74,7 @@ pub fn hash_stable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_ma
s.bound_impl( s.bound_impl(
quote!(::rustc_data_structures::stable_hasher::HashStable<__CTX>), quote!(::rustc_data_structures::stable_hasher::HashStable<__CTX>),
quote! { quote! {
#[inline]
fn hash_stable( fn hash_stable(
&self, &self,
__hcx: &mut __CTX, __hcx: &mut __CTX,
@ -119,6 +120,7 @@ pub fn hash_stable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::To
> >
), ),
quote! { quote! {
#[inline]
fn hash_stable( fn hash_stable(
&self, &self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>, __hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,

View File

@ -548,10 +548,12 @@ mod impls {
($(($ty:ident, $meth:ident),)*) => {$( ($(($ty:ident, $meth:ident),)*) => {$(
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Hash for $ty { impl Hash for $ty {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) { fn hash<H: Hasher>(&self, state: &mut H) {
state.$meth(*self) state.$meth(*self)
} }
#[inline]
fn hash_slice<H: Hasher>(data: &[$ty], state: &mut H) { fn hash_slice<H: Hasher>(data: &[$ty], state: &mut H) {
let newlen = data.len() * mem::size_of::<$ty>(); let newlen = data.len() * mem::size_of::<$ty>();
let ptr = data.as_ptr() as *const u8; let ptr = data.as_ptr() as *const u8;
@ -582,6 +584,7 @@ mod impls {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Hash for bool { impl Hash for bool {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) { fn hash<H: Hasher>(&self, state: &mut H) {
state.write_u8(*self as u8) state.write_u8(*self as u8)
} }
@ -589,6 +592,7 @@ mod impls {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Hash for char { impl Hash for char {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) { fn hash<H: Hasher>(&self, state: &mut H) {
state.write_u32(*self as u32) state.write_u32(*self as u32)
} }
@ -596,6 +600,7 @@ mod impls {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Hash for str { impl Hash for str {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) { fn hash<H: Hasher>(&self, state: &mut H) {
state.write(self.as_bytes()); state.write(self.as_bytes());
state.write_u8(0xff) state.write_u8(0xff)
@ -604,6 +609,7 @@ mod impls {
#[stable(feature = "never_hash", since = "1.29.0")] #[stable(feature = "never_hash", since = "1.29.0")]
impl Hash for ! { impl Hash for ! {
#[inline]
fn hash<H: Hasher>(&self, _: &mut H) { fn hash<H: Hasher>(&self, _: &mut H) {
*self *self
} }
@ -613,6 +619,7 @@ mod impls {
() => ( () => (
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Hash for () { impl Hash for () {
#[inline]
fn hash<H: Hasher>(&self, _state: &mut H) {} fn hash<H: Hasher>(&self, _state: &mut H) {}
} }
); );
@ -621,6 +628,7 @@ mod impls {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<$($name: Hash),+> Hash for ($($name,)+) where last_type!($($name,)+): ?Sized { impl<$($name: Hash),+> Hash for ($($name,)+) where last_type!($($name,)+): ?Sized {
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[inline]
fn hash<S: Hasher>(&self, state: &mut S) { fn hash<S: Hasher>(&self, state: &mut S) {
let ($(ref $name,)+) = *self; let ($(ref $name,)+) = *self;
$($name.hash(state);)+ $($name.hash(state);)+
@ -650,6 +658,7 @@ mod impls {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<T: Hash> Hash for [T] { impl<T: Hash> Hash for [T] {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) { fn hash<H: Hasher>(&self, state: &mut H) {
self.len().hash(state); self.len().hash(state);
Hash::hash_slice(self, state) Hash::hash_slice(self, state)
@ -658,6 +667,7 @@ mod impls {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized + Hash> Hash for &T { impl<T: ?Sized + Hash> Hash for &T {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) { fn hash<H: Hasher>(&self, state: &mut H) {
(**self).hash(state); (**self).hash(state);
} }
@ -665,6 +675,7 @@ mod impls {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized + Hash> Hash for &mut T { impl<T: ?Sized + Hash> Hash for &mut T {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) { fn hash<H: Hasher>(&self, state: &mut H) {
(**self).hash(state); (**self).hash(state);
} }
@ -672,6 +683,7 @@ mod impls {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> Hash for *const T { impl<T: ?Sized> Hash for *const T {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) { fn hash<H: Hasher>(&self, state: &mut H) {
#[cfg(not(bootstrap))] #[cfg(not(bootstrap))]
{ {
@ -701,6 +713,7 @@ mod impls {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> Hash for *mut T { impl<T: ?Sized> Hash for *mut T {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) { fn hash<H: Hasher>(&self, state: &mut H) {
#[cfg(not(bootstrap))] #[cfg(not(bootstrap))]
{ {