diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-19 10:00:24 +0200 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-20 09:28:13 +0200 |
| commit | 59ecff915ce3fbef44ca5591d69c2c908a88ca0b (patch) | |
| tree | 82d995279ade02f644f3a8ca4bf919fa2e713c97 /src/liballoc/sync.rs | |
| parent | 27f5d0f208e12176c614d6ffbd410f7b53ed9eed (diff) | |
| download | rust-59ecff915ce3fbef44ca5591d69c2c908a88ca0b.tar.gz rust-59ecff915ce3fbef44ca5591d69c2c908a88ca0b.zip | |
Arc: refactor data_offset{_sized}.
Diffstat (limited to 'src/liballoc/sync.rs')
| -rw-r--r-- | src/liballoc/sync.rs | 17 |
1 files changed, 9 insertions, 8 deletions
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<T: ?Sized> AsRef<T> for Arc<T> { #[stable(feature = "pin", since = "1.33.0")] impl<T: ?Sized> Unpin for Arc<T> { } -/// Computes the offset of the data field within ArcInner. +/// Computes the offset of the data field within `ArcInner`. unsafe fn data_offset<T: ?Sized>(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::<ArcInner<()>>(); - (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<T>() -> isize { - let align = align_of::<T>(); + data_offset_align(align_of::<T>()) +} + +fn data_offset_align(align: usize) -> isize { let layout = Layout::new::<ArcInner<()>>(); (layout.size() + layout.padding_needed_for(align)) as isize } |
