Skip to content

Commit 3f47d32

Browse files
pcwaltonhuonw
authored andcommitted
---
yaml --- r: 106997 b: refs/heads/try c: 0b714b4 h: refs/heads/master i: 106995: 584b056 v: v3
1 parent c959934 commit 3f47d32

File tree

6 files changed

+64
-84
lines changed

6 files changed

+64
-84
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: b8ef9fd9c9f642ce7b8aed82782a1ed745d08d64
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b8601a3d8b91ad3b653d143307611f2f5c75617e
5-
refs/heads/try: a0f943cd3a653064f8e25e408b6bf02e81bb4a1b
5+
refs/heads/try: 0b714b4ba6411c6997324d442a3df602e5920ff5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libstd/rc.rs

Lines changed: 34 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,18 @@ pointers, and then storing the parent pointers as `Weak` pointers.
2424
*/
2525

2626
use cast::transmute;
27-
use cell::Cell;
2827
use clone::Clone;
2928
use cmp::{Eq, Ord};
3029
use kinds::marker;
3130
use ops::{Deref, Drop};
3231
use option::{Option, Some, None};
3332
use ptr;
34-
use ptr::RawPtr;
3533
use rt::global_heap::exchange_free;
3634

3735
struct RcBox<T> {
3836
value: T,
39-
strong: Cell<uint>,
40-
weak: Cell<uint>
37+
strong: uint,
38+
weak: uint
4139
}
4240

4341
/// Immutable reference counted pointer type
@@ -58,11 +56,7 @@ impl<T> Rc<T> {
5856
// destructor never frees the allocation while the
5957
// strong destructor is running, even if the weak
6058
// pointer is stored inside the strong one.
61-
ptr: transmute(~RcBox {
62-
value: value,
63-
strong: Cell::new(1),
64-
weak: Cell::new(1)
65-
}),
59+
ptr: transmute(~RcBox { value: value, strong: 1, weak: 1 }),
6660
nosend: marker::NoSend,
6761
noshare: marker::NoShare
6862
}
@@ -73,11 +67,13 @@ impl<T> Rc<T> {
7367
impl<T> Rc<T> {
7468
/// Downgrade the reference-counted pointer to a weak reference
7569
pub fn downgrade(&self) -> Weak<T> {
76-
self.inc_weak();
77-
Weak {
78-
ptr: self.ptr,
79-
nosend: marker::NoSend,
80-
noshare: marker::NoShare
70+
unsafe {
71+
(*self.ptr).weak += 1;
72+
Weak {
73+
ptr: self.ptr,
74+
nosend: marker::NoSend,
75+
noshare: marker::NoShare
76+
}
8177
}
8278
}
8379
}
@@ -86,24 +82,24 @@ impl<T> Deref<T> for Rc<T> {
8682
/// Borrow the value contained in the reference-counted box
8783
#[inline(always)]
8884
fn deref<'a>(&'a self) -> &'a T {
89-
&self.inner().value
85+
unsafe { &(*self.ptr).value }
9086
}
9187
}
9288

9389
#[unsafe_destructor]
9490
impl<T> Drop for Rc<T> {
9591
fn drop(&mut self) {
9692
unsafe {
97-
if !self.ptr.is_null() {
98-
self.dec_strong();
99-
if self.strong() == 0 {
93+
if self.ptr != 0 as *mut RcBox<T> {
94+
(*self.ptr).strong -= 1;
95+
if (*self.ptr).strong == 0 {
10096
ptr::read(self.deref()); // destroy the contained object
10197

10298
// remove the implicit "strong weak" pointer now
10399
// that we've destroyed the contents.
104-
self.dec_weak();
100+
(*self.ptr).weak -= 1;
105101

106-
if self.weak() == 0 {
102+
if (*self.ptr).weak == 0 {
107103
exchange_free(self.ptr as *u8)
108104
}
109105
}
@@ -115,8 +111,10 @@ impl<T> Drop for Rc<T> {
115111
impl<T> Clone for Rc<T> {
116112
#[inline]
117113
fn clone(&self) -> Rc<T> {
118-
self.inc_strong();
119-
Rc { ptr: self.ptr, nosend: marker::NoSend, noshare: marker::NoShare }
114+
unsafe {
115+
(*self.ptr).strong += 1;
116+
Rc { ptr: self.ptr, nosend: marker::NoSend, noshare: marker::NoShare }
117+
}
120118
}
121119
}
122120

@@ -153,11 +151,13 @@ pub struct Weak<T> {
153151
impl<T> Weak<T> {
154152
/// Upgrade a weak reference to a strong reference
155153
pub fn upgrade(&self) -> Option<Rc<T>> {
156-
if self.strong() == 0 {
157-
None
158-
} else {
159-
self.inc_strong();
160-
Some(Rc { ptr: self.ptr, nosend: marker::NoSend, noshare: marker::NoShare })
154+
unsafe {
155+
if (*self.ptr).strong == 0 {
156+
None
157+
} else {
158+
(*self.ptr).strong += 1;
159+
Some(Rc { ptr: self.ptr, nosend: marker::NoSend, noshare: marker::NoShare })
160+
}
161161
}
162162
}
163163
}
@@ -166,11 +166,11 @@ impl<T> Weak<T> {
166166
impl<T> Drop for Weak<T> {
167167
fn drop(&mut self) {
168168
unsafe {
169-
if !self.ptr.is_null() {
170-
self.dec_weak();
169+
if self.ptr != 0 as *mut RcBox<T> {
170+
(*self.ptr).weak -= 1;
171171
// the weak count starts at 1, and will only go to
172172
// zero if all the strong pointers have disappeared.
173-
if self.weak() == 0 {
173+
if (*self.ptr).weak == 0 {
174174
exchange_free(self.ptr as *u8)
175175
}
176176
}
@@ -181,44 +181,13 @@ impl<T> Drop for Weak<T> {
181181
impl<T> Clone for Weak<T> {
182182
#[inline]
183183
fn clone(&self) -> Weak<T> {
184-
self.inc_weak();
185-
Weak { ptr: self.ptr, nosend: marker::NoSend, noshare: marker::NoShare }
184+
unsafe {
185+
(*self.ptr).weak += 1;
186+
Weak { ptr: self.ptr, nosend: marker::NoSend, noshare: marker::NoShare }
187+
}
186188
}
187189
}
188190

189-
#[allow(missing_doc)]
190-
trait RcBoxPtr<T> {
191-
fn inner<'a>(&'a self) -> &'a RcBox<T>;
192-
193-
#[inline]
194-
fn strong(&self) -> uint { self.inner().strong.get() }
195-
196-
#[inline]
197-
fn inc_strong(&self) { self.inner().strong.set(self.strong() + 1); }
198-
199-
#[inline]
200-
fn dec_strong(&self) { self.inner().strong.set(self.strong() - 1); }
201-
202-
#[inline]
203-
fn weak(&self) -> uint { self.inner().weak.get() }
204-
205-
#[inline]
206-
fn inc_weak(&self) { self.inner().weak.set(self.weak() + 1); }
207-
208-
#[inline]
209-
fn dec_weak(&self) { self.inner().weak.set(self.weak() - 1); }
210-
}
211-
212-
impl<T> RcBoxPtr<T> for Rc<T> {
213-
#[inline(always)]
214-
fn inner<'a>(&'a self) -> &'a RcBox<T> { unsafe { &(*self.ptr) } }
215-
}
216-
217-
impl<T> RcBoxPtr<T> for Weak<T> {
218-
#[inline(always)]
219-
fn inner<'a>(&'a self) -> &'a RcBox<T> { unsafe { &(*self.ptr) } }
220-
}
221-
222191
#[cfg(test)]
223192
mod tests {
224193
use prelude::*;

branches/try/src/libstd/rt/local_heap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rt::global_heap;
2121
use rt::local::Local;
2222
use rt::task::Task;
2323
use raw;
24-
use slice::ImmutableVector;
24+
use slice::{ImmutableVector, Vector};
2525
use vec::Vec;
2626

2727
// This has no meaning with out rtdebug also turned on.

branches/try/src/libstd/str.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ use ptr::RawPtr;
101101
use from_str::FromStr;
102102
use slice;
103103
use slice::{OwnedVector, OwnedCloneableVector, ImmutableVector, MutableVector};
104+
use slice::{Vector};
104105
use vec::Vec;
105106
use default::Default;
106107
use raw::Repr;

branches/try/src/libstd/vec.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use ptr;
2828
use rt::global_heap::{malloc_raw, realloc_raw};
2929
use raw::Slice;
3030
use slice::{ImmutableEqVector, ImmutableVector, Items, MutItems, MutableVector};
31-
use slice::{MutableTotalOrdVector};
31+
use slice::{MutableTotalOrdVector, Vector};
3232

3333
/// An owned, growable vector.
3434
///
@@ -534,22 +534,6 @@ impl<T> Vec<T> {
534534
self.len = len;
535535
}
536536

537-
/// Work with `self` as a slice.
538-
///
539-
/// # Example
540-
///
541-
/// ```rust
542-
/// fn foo(slice: &[int]) {}
543-
///
544-
/// let vec = vec!(1, 2);
545-
/// foo(vec.as_slice());
546-
/// ```
547-
#[inline]
548-
pub fn as_slice<'a>(&'a self) -> &'a [T] {
549-
let slice = Slice { data: self.ptr as *T, len: self.len };
550-
unsafe { transmute(slice) }
551-
}
552-
553537
/// Work with `self` as a mutable slice.
554538
///
555539
/// # Example
@@ -1172,6 +1156,24 @@ impl<T:Eq> Vec<T> {
11721156
}
11731157
}
11741158

1159+
impl<T> Vector<T> for Vec<T> {
1160+
/// Work with `self` as a slice.
1161+
///
1162+
/// # Example
1163+
///
1164+
/// ```rust
1165+
/// fn foo(slice: &[int]) {}
1166+
///
1167+
/// let vec = vec!(1, 2);
1168+
/// foo(vec.as_slice());
1169+
/// ```
1170+
#[inline]
1171+
fn as_slice<'a>(&'a self) -> &'a [T] {
1172+
let slice = Slice { data: self.ptr as *T, len: self.len };
1173+
unsafe { transmute(slice) }
1174+
}
1175+
}
1176+
11751177
/// Iterates over the `second` vector, copying each element and appending it to
11761178
/// the `first`. Afterwards, the `first` is then returned for use again.
11771179
///

branches/try/src/libsyntax/ast.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,14 @@ mod test {
11561156
use codemap::*;
11571157
use super::*;
11581158

1159+
fn is_freeze<T: Freeze>() {}
1160+
1161+
// Assert that the AST remains Freeze (#10693).
1162+
#[test]
1163+
fn ast_is_freeze() {
1164+
is_freeze::<Item>();
1165+
}
1166+
11591167
// are ASTs encodable?
11601168
#[test]
11611169
fn check_asts_encodable() {

0 commit comments

Comments
 (0)