diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-19 04:48:46 +0200 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-20 09:28:12 +0200 |
| commit | 2efbc9e5a2c5ae36ed2de0b23f315a5d6853b747 (patch) | |
| tree | c5bcb6b1199a0d497a551e4aab12fcb1ec3afaeb /src/liballoc | |
| parent | 19982f5653946b9d770f35560115ccc7a25356d4 (diff) | |
| download | rust-2efbc9e5a2c5ae36ed2de0b23f315a5d6853b747.tar.gz rust-2efbc9e5a2c5ae36ed2de0b23f315a5d6853b747.zip | |
Rc: refactor data_offset{_sized}.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/rc.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index f9af752cae6..252b1c5a6dc 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -2176,18 +2176,19 @@ impl<T: ?Sized> AsRef<T> for Rc<T> { impl<T: ?Sized> Unpin for Rc<T> { } unsafe fn data_offset<T: ?Sized>(ptr: *const T) -> isize { - // Align the unsized value to the end of the RcBox. + // Align the unsized value to the end of the `RcBox`. // Because it is ?Sized, it will always be the last field in memory. - let align = align_of_val(&*ptr); - let layout = Layout::new::<RcBox<()>>(); - (layout.size() + layout.padding_needed_for(align)) as isize + data_offset_align(align_of_val(&*ptr)) } -/// Computes the offset of the data field within ArcInner. +/// Computes the offset of the data field within `RcBox`. /// /// 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::<RcBox<()>>(); (layout.size() + layout.padding_needed_for(align)) as isize } |
