Skip to content

Commit 19b40f7

Browse files
committed
Rollup merge of #23495 - pcwalton:inline-cell, r=cmr
This is a significant performance problem in Servo. r? @brson
2 parents 288acc7 + 592e7ff commit 19b40f7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/libcore/cell.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ impl<T:Copy> Cell<T> {
168168
/// let c = Cell::new(5);
169169
/// ```
170170
#[stable(feature = "rust1", since = "1.0.0")]
171+
#[inline]
171172
pub fn new(value: T) -> Cell<T> {
172173
Cell {
173174
value: UnsafeCell::new(value),
@@ -237,6 +238,7 @@ unsafe impl<T> Send for Cell<T> where T: Send {}
237238

238239
#[stable(feature = "rust1", since = "1.0.0")]
239240
impl<T:Copy> Clone for Cell<T> {
241+
#[inline]
240242
fn clone(&self) -> Cell<T> {
241243
Cell::new(self.get())
242244
}
@@ -245,13 +247,15 @@ impl<T:Copy> Clone for Cell<T> {
245247
#[stable(feature = "rust1", since = "1.0.0")]
246248
impl<T:Default + Copy> Default for Cell<T> {
247249
#[stable(feature = "rust1", since = "1.0.0")]
250+
#[inline]
248251
fn default() -> Cell<T> {
249252
Cell::new(Default::default())
250253
}
251254
}
252255

253256
#[stable(feature = "rust1", since = "1.0.0")]
254257
impl<T:PartialEq + Copy> PartialEq for Cell<T> {
258+
#[inline]
255259
fn eq(&self, other: &Cell<T>) -> bool {
256260
self.get() == other.get()
257261
}
@@ -295,6 +299,7 @@ impl<T> RefCell<T> {
295299
/// let c = RefCell::new(5);
296300
/// ```
297301
#[stable(feature = "rust1", since = "1.0.0")]
302+
#[inline]
298303
pub fn new(value: T) -> RefCell<T> {
299304
RefCell {
300305
value: UnsafeCell::new(value),
@@ -314,6 +319,7 @@ impl<T> RefCell<T> {
314319
/// let five = c.into_inner();
315320
/// ```
316321
#[stable(feature = "rust1", since = "1.0.0")]
322+
#[inline]
317323
pub fn into_inner(self) -> T {
318324
// Since this function takes `self` (the `RefCell`) by value, the
319325
// compiler statically verifies that it is not currently borrowed.
@@ -327,6 +333,7 @@ impl<T> RefCell<T> {
327333
/// The returned value can be dispatched on to determine if a call to
328334
/// `borrow` or `borrow_mut` would succeed.
329335
#[unstable(feature = "std_misc")]
336+
#[inline]
330337
pub fn borrow_state(&self) -> BorrowState {
331338
match self.borrow.get() {
332339
WRITING => BorrowState::Writing,
@@ -344,6 +351,7 @@ impl<T> RefCell<T> {
344351
#[unstable(feature = "core", reason = "may be renamed or removed")]
345352
#[deprecated(since = "1.0.0",
346353
reason = "dispatch on `cell.borrow_state()` instead")]
354+
#[inline]
347355
pub fn try_borrow<'a>(&'a self) -> Option<Ref<'a, T>> {
348356
match BorrowRef::new(&self.borrow) {
349357
Some(b) => Some(Ref { _value: unsafe { &*self.value.get() }, _borrow: b }),
@@ -387,6 +395,7 @@ impl<T> RefCell<T> {
387395
/// assert!(result.is_err());
388396
/// ```
389397
#[stable(feature = "rust1", since = "1.0.0")]
398+
#[inline]
390399
pub fn borrow<'a>(&'a self) -> Ref<'a, T> {
391400
match BorrowRef::new(&self.borrow) {
392401
Some(b) => Ref {
@@ -406,6 +415,7 @@ impl<T> RefCell<T> {
406415
#[unstable(feature = "core", reason = "may be renamed or removed")]
407416
#[deprecated(since = "1.0.0",
408417
reason = "dispatch on `cell.borrow_state()` instead")]
418+
#[inline]
409419
pub fn try_borrow_mut<'a>(&'a self) -> Option<RefMut<'a, T>> {
410420
match BorrowRefMut::new(&self.borrow) {
411421
Some(b) => Some(RefMut { _value: unsafe { &mut *self.value.get() }, _borrow: b }),
@@ -448,6 +458,7 @@ impl<T> RefCell<T> {
448458
/// assert!(result.is_err());
449459
/// ```
450460
#[stable(feature = "rust1", since = "1.0.0")]
461+
#[inline]
451462
pub fn borrow_mut<'a>(&'a self) -> RefMut<'a, T> {
452463
match BorrowRefMut::new(&self.borrow) {
453464
Some(b) => RefMut {
@@ -475,6 +486,7 @@ unsafe impl<T> Send for RefCell<T> where T: Send {}
475486

476487
#[stable(feature = "rust1", since = "1.0.0")]
477488
impl<T: Clone> Clone for RefCell<T> {
489+
#[inline]
478490
fn clone(&self) -> RefCell<T> {
479491
RefCell::new(self.borrow().clone())
480492
}
@@ -483,13 +495,15 @@ impl<T: Clone> Clone for RefCell<T> {
483495
#[stable(feature = "rust1", since = "1.0.0")]
484496
impl<T:Default> Default for RefCell<T> {
485497
#[stable(feature = "rust1", since = "1.0.0")]
498+
#[inline]
486499
fn default() -> RefCell<T> {
487500
RefCell::new(Default::default())
488501
}
489502
}
490503

491504
#[stable(feature = "rust1", since = "1.0.0")]
492505
impl<T: PartialEq> PartialEq for RefCell<T> {
506+
#[inline]
493507
fn eq(&self, other: &RefCell<T>) -> bool {
494508
*self.borrow() == *other.borrow()
495509
}
@@ -500,6 +514,7 @@ struct BorrowRef<'b> {
500514
}
501515

502516
impl<'b> BorrowRef<'b> {
517+
#[inline]
503518
fn new(borrow: &'b Cell<BorrowFlag>) -> Option<BorrowRef<'b>> {
504519
match borrow.get() {
505520
WRITING => None,
@@ -513,6 +528,7 @@ impl<'b> BorrowRef<'b> {
513528

514529
#[unsafe_destructor]
515530
impl<'b> Drop for BorrowRef<'b> {
531+
#[inline]
516532
fn drop(&mut self) {
517533
let borrow = self._borrow.get();
518534
debug_assert!(borrow != WRITING && borrow != UNUSED);
@@ -521,6 +537,7 @@ impl<'b> Drop for BorrowRef<'b> {
521537
}
522538

523539
impl<'b> Clone for BorrowRef<'b> {
540+
#[inline]
524541
fn clone(&self) -> BorrowRef<'b> {
525542
// Since this Ref exists, we know the borrow flag
526543
// is not set to WRITING.
@@ -561,6 +578,7 @@ impl<'b, T> Deref for Ref<'b, T> {
561578
/// use of `r.borrow().clone()` to clone the contents of a `RefCell`.
562579
#[unstable(feature = "core",
563580
reason = "likely to be moved to a method, pending language changes")]
581+
#[inline]
564582
pub fn clone_ref<'b, T:Clone>(orig: &Ref<'b, T>) -> Ref<'b, T> {
565583
Ref {
566584
_value: orig._value,
@@ -574,6 +592,7 @@ struct BorrowRefMut<'b> {
574592

575593
#[unsafe_destructor]
576594
impl<'b> Drop for BorrowRefMut<'b> {
595+
#[inline]
577596
fn drop(&mut self) {
578597
let borrow = self._borrow.get();
579598
debug_assert!(borrow == WRITING);
@@ -582,6 +601,7 @@ impl<'b> Drop for BorrowRefMut<'b> {
582601
}
583602

584603
impl<'b> BorrowRefMut<'b> {
604+
#[inline]
585605
fn new(borrow: &'b Cell<BorrowFlag>) -> Option<BorrowRefMut<'b>> {
586606
match borrow.get() {
587607
UNUSED => {
@@ -674,6 +694,7 @@ impl<T> UnsafeCell<T> {
674694
/// let uc = UnsafeCell::new(5);
675695
/// ```
676696
#[stable(feature = "rust1", since = "1.0.0")]
697+
#[inline]
677698
pub fn new(value: T) -> UnsafeCell<T> {
678699
UnsafeCell { value: value }
679700
}

0 commit comments

Comments
 (0)