From 59ecff915ce3fbef44ca5591d69c2c908a88ca0b Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 19 Jun 2019 10:00:24 +0200 Subject: Arc: refactor data_offset{_sized}. --- src/liballoc/sync.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/liballoc/sync.rs') diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index de47e164c92..127068284d3 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -2298,20 +2298,21 @@ impl AsRef for Arc { #[stable(feature = "pin", since = "1.33.0")] impl Unpin for Arc { } -/// Computes the offset of the data field within ArcInner. +/// Computes the offset of the data field within `ArcInner`. unsafe fn data_offset(ptr: *const T) -> isize { - // Align the unsized value to the end of the ArcInner. - // Because it is ?Sized, it will always be the last field in memory. - let align = align_of_val(&*ptr); - let layout = Layout::new::>(); - (layout.size() + layout.padding_needed_for(align)) as isize + // Align the unsized value to the end of the `ArcInner`. + // Because it is `?Sized`, it will always be the last field in memory. + data_offset_align(align_of_val(&*ptr)) } -/// Computes the offset of the data field within ArcInner. +/// Computes the offset of the data field within `ArcInner`. /// /// Unlike [`data_offset`], this doesn't need the pointer, but it works only on `T: Sized`. fn data_offset_sized() -> isize { - let align = align_of::(); + data_offset_align(align_of::()) +} + +fn data_offset_align(align: usize) -> isize { let layout = Layout::new::>(); (layout.size() + layout.padding_needed_for(align)) as isize } -- cgit 1.4.1-3-g733a5