Skip to content

Commit 1a76f3d

Browse files
committed
Auto merge of rust-lang#132553 - EFanZh:zero-cost-rc-arc-deref, r=<try>
Make `Rc<T>::deref` and `Arc<T>::deref` zero-cost Currently, `Rc<T>` and `Arc<T>` store pointers to `RcInner<T>` and `ArcInner<T>`. This PR changes the pointers so that they point to `T` directly instead. This is based on the assumption that we access the `T` value more frequently than accessing reference counts. With this change, accessing the data can be done without offsetting pointers from `RcInner<T>` and `ArcInner<T>` to their contained data. This change might also enables some possibly useful future optimizations, such as: - Convert `&[Rc<T>]` into `&[&T]` within O(1) time. - Convert `&[Rc<T>]` into `Vec<&T>` utilizing `memcpy`. - Convert `&Option<Rc<T>>` into `Option<&T>` without branching. - Make `Rc<T>` and `Arc<T>` FFI compatible types where `T: Sized`.
2 parents b880760 + ae9240c commit 1a76f3d

File tree

13 files changed

+3379
-2426
lines changed

13 files changed

+3379
-2426
lines changed

library/alloc/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ mod testing;
212212
#[macro_use]
213213
mod macros;
214214

215+
#[cfg(not(no_rc))]
216+
mod raw_rc;
215217
mod raw_vec;
216218

217219
// Heaps provided for low-level allocation strategies

library/alloc/src/raw_rc.rs

+2,468
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)