Skip to content

Commit ab63188

Browse files
committed
libcore: De-mode at_vec
1 parent cac5a9f commit ab63188

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/libcore/at_vec.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
//! Managed vectors
22
3+
// NB: transitionary, de-mode-ing.
4+
#[forbid(deprecated_mode)];
5+
#[forbid(deprecated_pattern)];
6+
37
use ptr::addr_of;
48

59
/// Code for dealing with @-vectors. This is pretty incomplete, and
@@ -21,7 +25,7 @@ extern mod rusti {
2125

2226
/// Returns the number of elements the vector can hold without reallocating
2327
#[inline(always)]
24-
pub pure fn capacity<T>(&&v: @[const T]) -> uint {
28+
pub pure fn capacity<T>(v: @[const T]) -> uint {
2529
unsafe {
2630
let repr: **raw::VecRepr =
2731
::cast::reinterpret_cast(&addr_of(v));
@@ -43,7 +47,7 @@ pub pure fn capacity<T>(&&v: @[const T]) -> uint {
4347
*/
4448
#[inline(always)]
4549
pub pure fn build_sized<A>(size: uint,
46-
builder: fn(push: pure fn(+v: A))) -> @[A] {
50+
builder: &fn(push: pure fn(+v: A))) -> @[A] {
4751
let mut vec = @[];
4852
unsafe { raw::reserve(vec, size); }
4953
builder(|+x| unsafe { raw::push(vec, move x) });
@@ -61,7 +65,7 @@ pub pure fn build_sized<A>(size: uint,
6165
* onto the vector being constructed.
6266
*/
6367
#[inline(always)]
64-
pub pure fn build<A>(builder: fn(push: pure fn(+v: A))) -> @[A] {
68+
pub pure fn build<A>(builder: &fn(push: pure fn(+v: A))) -> @[A] {
6569
build_sized(4, builder)
6670
}
6771

@@ -78,8 +82,8 @@ pub pure fn build<A>(builder: fn(push: pure fn(+v: A))) -> @[A] {
7882
* onto the vector being constructed.
7983
*/
8084
#[inline(always)]
81-
pub pure fn build_sized_opt<A>(size: Option<uint>,
82-
builder: fn(push: pure fn(+v: A))) -> @[A] {
85+
pub pure fn build_sized_opt<A>(+size: Option<uint>,
86+
builder: &fn(push: pure fn(+v: A))) -> @[A] {
8387
build_sized(size.get_default(4), builder)
8488
}
8589

@@ -94,10 +98,10 @@ pub pure fn append<T: Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
9498

9599

96100
/// Apply a function to each element of a vector and return the results
97-
pub pure fn map<T, U>(v: &[T], f: fn(T) -> U) -> @[U] {
101+
pub pure fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
98102
do build_sized(v.len()) |push| {
99103
for vec::each(v) |elem| {
100-
push(f(*elem));
104+
push(f(elem));
101105
}
102106
}
103107
}
@@ -121,10 +125,10 @@ pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
121125
* Creates an immutable vector of size `n_elts` and initializes the elements
122126
* to the value `t`.
123127
*/
124-
pub pure fn from_elem<T: Copy>(n_elts: uint, t: T) -> @[T] {
128+
pub pure fn from_elem<T: Copy>(n_elts: uint, t: &T) -> @[T] {
125129
do build_sized(n_elts) |push| {
126130
let mut i: uint = 0u;
127-
while i < n_elts { push(t); i += 1u; }
131+
while i < n_elts { push(copy *t); i += 1u; }
128132
}
129133
}
130134

@@ -155,13 +159,13 @@ pub mod raw {
155159
* the vector is actually the specified size.
156160
*/
157161
#[inline(always)]
158-
pub unsafe fn set_len<T>(&&v: @[const T], new_len: uint) {
162+
pub unsafe fn set_len<T>(v: @[const T], new_len: uint) {
159163
let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v));
160164
(**repr).unboxed.fill = new_len * sys::size_of::<T>();
161165
}
162166

163167
#[inline(always)]
164-
pub unsafe fn push<T>(&v: @[const T], +initval: T) {
168+
pub unsafe fn push<T>(v: @[const T], +initval: T) {
165169
let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v));
166170
let fill = (**repr).unboxed.fill;
167171
if (**repr).unboxed.alloc > fill {
@@ -173,7 +177,7 @@ pub mod raw {
173177
}
174178
// This doesn't bother to make sure we have space.
175179
#[inline(always)] // really pretty please
176-
pub unsafe fn push_fast<T>(&v: @[const T], +initval: T) {
180+
pub unsafe fn push_fast<T>(v: @[const T], +initval: T) {
177181
let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v));
178182
let fill = (**repr).unboxed.fill;
179183
(**repr).unboxed.fill += sys::size_of::<T>();
@@ -182,7 +186,7 @@ pub mod raw {
182186
rusti::move_val_init(*p, move initval);
183187
}
184188

185-
pub unsafe fn push_slow<T>(&v: @[const T], +initval: T) {
189+
pub unsafe fn push_slow<T>(v: @[const T], +initval: T) {
186190
reserve_at_least(v, v.len() + 1u);
187191
push_fast(v, move initval);
188192
}
@@ -198,7 +202,7 @@ pub mod raw {
198202
* * v - A vector
199203
* * n - The number of elements to reserve space for
200204
*/
201-
pub unsafe fn reserve<T>(&v: @[const T], n: uint) {
205+
pub unsafe fn reserve<T>(v: @[const T], n: uint) {
202206
// Only make the (slow) call into the runtime if we have to
203207
if capacity(v) < n {
204208
let ptr = addr_of(v) as **VecRepr;
@@ -222,7 +226,7 @@ pub mod raw {
222226
* * v - A vector
223227
* * n - The number of elements to reserve space for
224228
*/
225-
pub unsafe fn reserve_at_least<T>(&v: @[const T], n: uint) {
229+
pub unsafe fn reserve_at_least<T>(v: @[const T], n: uint) {
226230
reserve(v, uint::next_power_of_two(n));
227231
}
228232

src/libcore/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The iteration traits and common implementation
77
use cmp::{Eq, Ord};
88

99
/// A function used to initialize the elements of a sequence
10-
type InitOp<T> = fn(uint) -> T;
10+
type InitOp<T> = &fn(uint) -> T;
1111

1212
trait BaseIter<A> {
1313
pure fn each(blk: fn(v: &A) -> bool);

0 commit comments

Comments
 (0)