Skip to content

Commit 2efbc9e

Browse files
committed
Rc: refactor data_offset{_sized}.
1 parent 19982f5 commit 2efbc9e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/liballoc/rc.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,18 +2176,19 @@ impl<T: ?Sized> AsRef<T> for Rc<T> {
21762176
impl<T: ?Sized> Unpin for Rc<T> { }
21772177

21782178
unsafe fn data_offset<T: ?Sized>(ptr: *const T) -> isize {
2179-
// Align the unsized value to the end of the RcBox.
2179+
// Align the unsized value to the end of the `RcBox`.
21802180
// Because it is ?Sized, it will always be the last field in memory.
2181-
let align = align_of_val(&*ptr);
2182-
let layout = Layout::new::<RcBox<()>>();
2183-
(layout.size() + layout.padding_needed_for(align)) as isize
2181+
data_offset_align(align_of_val(&*ptr))
21842182
}
21852183

2186-
/// Computes the offset of the data field within ArcInner.
2184+
/// Computes the offset of the data field within `RcBox`.
21872185
///
21882186
/// Unlike [`data_offset`], this doesn't need the pointer, but it works only on `T: Sized`.
21892187
fn data_offset_sized<T>() -> isize {
2190-
let align = align_of::<T>();
2188+
data_offset_align(align_of::<T>())
2189+
}
2190+
2191+
fn data_offset_align(align: usize) -> isize {
21912192
let layout = Layout::new::<RcBox<()>>();
21922193
(layout.size() + layout.padding_needed_for(align)) as isize
21932194
}

0 commit comments

Comments
 (0)