-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance audit, Spring 2017 #41410
Changes from all commits
64c6978
02ad572
f3682e5
22328a5
7aaf841
32ca8c5
dae49f1
1b207ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,7 +239,7 @@ use core::ops::CoerceUnsized; | |
use core::ptr::{self, Shared}; | ||
use core::convert::From; | ||
|
||
use heap::deallocate; | ||
use heap::{allocate, deallocate, box_free}; | ||
use raw_vec::RawVec; | ||
|
||
struct RcBox<T: ?Sized> { | ||
|
@@ -248,7 +248,6 @@ struct RcBox<T: ?Sized> { | |
value: T, | ||
} | ||
|
||
|
||
/// A single-threaded reference-counting pointer. | ||
/// | ||
/// See the [module-level documentation](./index.html) for more details. | ||
|
@@ -438,6 +437,38 @@ impl Rc<str> { | |
} | ||
} | ||
|
||
impl<T> Rc<[T]> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, for the purposes of the compiler, does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may also be more easily implementable by consuming There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't bother checking. But |
||
/// Constructs a new `Rc<[T]>` from a `Box<[T]>`. | ||
#[doc(hidden)] | ||
#[unstable(feature = "rustc_private", | ||
reason = "for internal use in rustc", | ||
issue = "0")] | ||
pub fn __from_array(value: Box<[T]>) -> Rc<[T]> { | ||
unsafe { | ||
let ptr: *mut RcBox<[T]> = | ||
mem::transmute([mem::align_of::<RcBox<[T; 1]>>(), value.len()]); | ||
// FIXME(custom-DST): creating this invalid &[T] is dubiously defined, | ||
// we should have a better way of getting the size/align | ||
// of a DST from its unsized part. | ||
let ptr = allocate(size_of_val(&*ptr), align_of_val(&*ptr)); | ||
let ptr: *mut RcBox<[T]> = mem::transmute([ptr as usize, value.len()]); | ||
|
||
// Initialize the new RcBox. | ||
ptr::write(&mut (*ptr).strong, Cell::new(1)); | ||
ptr::write(&mut (*ptr).weak, Cell::new(1)); | ||
ptr::copy_nonoverlapping( | ||
value.as_ptr(), | ||
&mut (*ptr).value as *mut [T] as *mut T, | ||
value.len()); | ||
|
||
// Free the original allocation without freeing its (moved) contents. | ||
box_free(Box::into_raw(value)); | ||
|
||
Rc { ptr: Shared::new(ptr as *const _) } | ||
} | ||
} | ||
} | ||
|
||
impl<T: ?Sized> Rc<T> { | ||
/// Creates a new [`Weak`][weak] pointer to this value. | ||
/// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -871,8 +871,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { | |
// we can promote to a constant, otherwise equal to enclosing temp | ||
// lifetime. | ||
let (re, old_re) = if promotable { | ||
(self.tcx().mk_region(ty::ReStatic), | ||
self.tcx().mk_region(ty::ReStatic)) | ||
(self.tcx().types.re_static, | ||
self.tcx().types.re_static) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just noticed that we don't have these constants pre-interned. This is going to conflict like hell with one of my in-progress branches, but oh well. =) |
||
} else { | ||
self.temporary_scope(id) | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -410,7 +410,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { | |
pub fn erase_late_bound_regions<T>(self, value: &Binder<T>) -> T | ||
where T : TypeFoldable<'tcx> | ||
{ | ||
self.replace_late_bound_regions(value, |_| self.mk_region(ty::ReErased)).0 | ||
self.replace_late_bound_regions(value, |_| self.types.re_erased).0 | ||
} | ||
|
||
/// Rewrite any late-bound regions so that they are anonymous. Region numbers are | ||
|
@@ -538,7 +538,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { | |
// whenever a substitution occurs. | ||
match *r { | ||
ty::ReLateBound(..) => r, | ||
_ => self.tcx().mk_region(ty::ReErased) | ||
_ => self.tcx().types.re_erased | ||
} | ||
} | ||
} | ||
|
@@ -565,6 +565,22 @@ pub fn shift_region(region: ty::Region, amount: u32) -> ty::Region { | |
} | ||
} | ||
|
||
pub fn shift_region_ref<'a, 'gcx, 'tcx>( | ||
tcx: TyCtxt<'a, 'gcx, 'tcx>, | ||
region: &'tcx ty::Region, | ||
amount: u32) | ||
-> &'tcx ty::Region | ||
{ | ||
match region { | ||
&ty::ReLateBound(debruijn, br) if amount > 0 => { | ||
tcx.mk_region(ty::ReLateBound(debruijn.shifted(amount), br)) | ||
} | ||
_ => { | ||
region | ||
} | ||
} | ||
} | ||
|
||
pub fn shift_regions<'a, 'gcx, 'tcx, T>(tcx: TyCtxt<'a, 'gcx, 'tcx>, | ||
amount: u32, value: &T) -> T | ||
where T: TypeFoldable<'tcx> | ||
|
@@ -573,7 +589,7 @@ pub fn shift_regions<'a, 'gcx, 'tcx, T>(tcx: TyCtxt<'a, 'gcx, 'tcx>, | |
value, amount); | ||
|
||
value.fold_with(&mut RegionFolder::new(tcx, &mut false, &mut |region, _current_depth| { | ||
tcx.mk_region(shift_region(*region, amount)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wow. By-value |
||
shift_region_ref(tcx, region, amount) | ||
})) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two functions are not imported during testing (so this fails to compile then).