Skip to content

Commit 2f90444

Browse files
committed
---
yaml --- r: 11591 b: refs/heads/master c: 3ed6f65 h: refs/heads/master i: 11589: 4f451ad 11587: 854f371 11583: 34fa844 v: v3
1 parent 67bad15 commit 2f90444

File tree

19 files changed

+59
-118
lines changed

19 files changed

+59
-118
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 47e7a05a28c9662159af2d2e0f2b7efc13fa09cb
2+
refs/heads/master: 3ed6f6520f56204f1c7c799ec8fa231bef0fb4d1
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/comp/middle/check_alt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn check_exhaustive(tcx: ty::ctxt, sp: span, pats: [@pat]) {
8888
}));
8989
}
9090
ty::ty_tup(ts) {
91-
let cols = vec::init_elt_mut(ts.len(), []);
91+
let cols = vec::to_mut(vec::init_elt(ts.len(), []));
9292
for p in pats {
9393
alt raw_pat(p).node {
9494
pat_tup(sub) {
@@ -156,7 +156,7 @@ fn check_exhaustive_enum(tcx: ty::ctxt, enum_id: def_id, sp: span,
156156
let variants = enum_variants(tcx, enum_id);
157157
let columns_by_variant = vec::map(*variants, {|v|
158158
{mutable seen: false,
159-
cols: vec::init_elt_mut(v.args.len(), [])}
159+
cols: vec::to_mut(vec::init_elt(v.args.len(), []))}
160160
});
161161

162162
for pat in pats {

trunk/src/comp/middle/trans/alt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ fn pick_col(m: match) -> uint {
337337
_ { 0u }
338338
}
339339
}
340-
let scores = vec::init_elt_mut(m[0].pats.len(), 0u);
340+
let scores = vec::to_mut(vec::init_elt(m[0].pats.len(), 0u));
341341
for br: match_branch in m {
342342
let i = 0u;
343343
for p: @ast::pat in br.pats { scores[i] += score(p); i += 1u; }

trunk/src/comp/middle/trans/base.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,9 @@ fn make_generic_glue_inner(ccx: crate_ctxt, t: ty::t,
741741
p += 1u;
742742
}
743743

744-
fcx.lltyparams = vec::map_mut(lltydescs, {|d| {desc: d, dicts: none}});
744+
fcx.lltyparams = vec::map(vec::from_mut(lltydescs), {|d|
745+
{desc: d, dicts: none}
746+
});
745747

746748
let bcx = top_scope_block(fcx, none);
747749
let lltop = bcx.llbb;

trunk/src/comp/middle/tstate/auxiliary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ fn get_fn_info(ccx: crate_ctxt, id: node_id) -> fn_info {
294294
fn add_node(ccx: crate_ctxt, i: node_id, a: ts_ann) {
295295
let sz = vec::len(*ccx.node_anns);
296296
if sz <= i as uint {
297-
vec::grow_mut(*ccx.node_anns, (i as uint) - sz + 1u, empty_ann(0u));
297+
vec::grow(*ccx.node_anns, (i as uint) - sz + 1u, empty_ann(0u));
298298
}
299299
ccx.node_anns[i] = a;
300300
}

trunk/src/comp/syntax/print/pp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ fn mk_printer(out: io::writer, linewidth: uint) -> printer {
101101
// fall behind.
102102
let n: uint = 3u * linewidth;
103103
#debug("mk_printer %u", linewidth);
104-
let token: [mutable token] = vec::init_elt_mut(n, EOF);
105-
let size: [mutable int] = vec::init_elt_mut(n, 0);
106-
let scan_stack: [mutable uint] = vec::init_elt_mut(n, 0u);
104+
let token: [mutable token] = vec::to_mut(vec::init_elt(n, EOF));
105+
let size: [mutable int] = vec::to_mut(vec::init_elt(n, 0));
106+
let scan_stack: [mutable uint] = vec::to_mut(vec::init_elt(n, 0u));
107107
let print_stack: [print_stack_elt] = [];
108108
@{out: out,
109109
buf_len: n,

trunk/src/compiletest/runtest.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ fn check_expected_errors(expected_errors: [errors::expected_error],
229229
procres: procres) {
230230

231231
// true if we found the error in question
232-
let found_flags = vec::init_elt_mut(vec::len(expected_errors), false);
232+
let found_flags = vec::to_mut(vec::init_elt(
233+
vec::len(expected_errors), false));
233234

234235
if procres.status == 0 {
235236
fatal("process did not return an error status");

trunk/src/libcore/vec.rs

Lines changed: 20 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,6 @@ fn init_fn<T>(n_elts: uint, op: init_op<T>) -> [T] {
9696
ret v;
9797
}
9898

99-
// TODO: Remove me once we have slots.
100-
/*
101-
Function: init_fn_mut
102-
103-
Creates and initializes a mutable vector.
104-
105-
Creates a mutable vector of size `n_elts` and initializes the elements to
106-
the value returned by the function `op`.
107-
*/
108-
fn init_fn_mut<T>(n_elts: uint, op: init_op<T>) -> [mutable T] {
109-
let v = [mutable];
110-
reserve(v, n_elts);
111-
let i: uint = 0u;
112-
while i < n_elts { v += [mutable op(i)]; i += 1u; }
113-
ret v;
114-
}
115-
11699
/*
117100
Function: init_elt
118101
@@ -129,27 +112,10 @@ fn init_elt<T: copy>(n_elts: uint, t: T) -> [T] {
129112
ret v;
130113
}
131114

132-
// TODO: Remove me once we have slots.
133-
/*
134-
Function: init_elt_mut
135-
136-
Creates and initializes a mutable vector.
137-
138-
Creates a mutable vector of size `n_elts` and initializes the elements
139-
to the value `t`.
140-
*/
141-
fn init_elt_mut<T: copy>(n_elts: uint, t: T) -> [mutable T] {
142-
let v = [mutable];
143-
reserve(v, n_elts);
144-
let i: uint = 0u;
145-
while i < n_elts { v += [mutable t]; i += 1u; }
146-
ret v;
147-
}
148-
149115
// FIXME: Possible typestate postcondition:
150116
// len(result) == len(v) (needs issue #586)
151117
/*
152-
Function: to_mut
118+
153119
154120
Produces a mutable vector from an immutable vector.
155121
*/
@@ -257,22 +223,6 @@ fn slice<T: copy>(v: [const T], start: uint, end: uint) -> [T] {
257223
ret result;
258224
}
259225

260-
// TODO: Remove me once we have slots.
261-
/*
262-
Function: slice_mut
263-
264-
Returns a copy of the elements from [`start`..`end`) from `v`.
265-
*/
266-
fn slice_mut<T: copy>(v: [const T], start: uint, end: uint) -> [mutable T] {
267-
assert (start <= end);
268-
assert (end <= len(v));
269-
let result = [mutable];
270-
reserve(result, end - start);
271-
let i = start;
272-
while i < end { result += [mutable v[i]]; i += 1u; }
273-
ret result;
274-
}
275-
276226
/*
277227
Function: split
278228
@@ -438,25 +388,6 @@ fn grow<T: copy>(&v: [const T], n: uint, initval: T) {
438388
while i < n { v += [initval]; i += 1u; }
439389
}
440390

441-
// TODO: Remove me once we have slots.
442-
// FIXME: Can't grow take a [const T]
443-
/*
444-
Function: grow_mut
445-
446-
Expands a vector in place, initializing the new elements to a given value
447-
448-
Parameters:
449-
450-
v - The vector to grow
451-
n - The number of elements to add
452-
initval - The value for the new elements
453-
*/
454-
fn grow_mut<T: copy>(&v: [mutable T], n: uint, initval: T) {
455-
reserve(v, next_power_of_two(len(v) + n));
456-
let i: uint = 0u;
457-
while i < n { v += [mutable initval]; i += 1u; }
458-
}
459-
460391
/*
461392
Function: grow_fn
462393
@@ -488,7 +419,7 @@ of the vector, expands the vector by replicating `initval` to fill the
488419
intervening space.
489420
*/
490421
fn grow_set<T: copy>(&v: [mutable T], index: uint, initval: T, val: T) {
491-
if index >= len(v) { grow_mut(v, index - len(v) + 1u, initval); }
422+
if index >= len(v) { grow(v, index - len(v) + 1u, initval); }
492423
v[index] = val;
493424
}
494425

@@ -507,21 +438,6 @@ fn map<T, U>(v: [T], f: fn(T) -> U) -> [U] {
507438
ret result;
508439
}
509440

510-
/*
511-
Function: map_mut
512-
513-
Apply a function to each element of a mutable vector and return the results
514-
*/
515-
fn map_mut<T: copy, U>(v: [const T], f: fn(T) -> U) -> [U] {
516-
let result = [];
517-
reserve(result, len(v));
518-
for elem: T in v {
519-
// copy satisfies alias checker
520-
result += [f(copy elem)];
521-
}
522-
ret result;
523-
}
524-
525441
/*
526442
Function: map2
527443
@@ -1949,6 +1865,24 @@ mod tests {
19491865
fn test_windowed_() {
19501866
let _x = windowed (0u, [1u,2u,3u,4u,5u,6u]);
19511867
}
1868+
1869+
#[test]
1870+
fn to_mut_no_copy() unsafe {
1871+
let x = [1, 2, 3];
1872+
let addr = unsafe::to_ptr(x);
1873+
let x_mut = to_mut(x);
1874+
let addr_mut = unsafe::to_ptr(x_mut);
1875+
assert addr == addr_mut;
1876+
}
1877+
1878+
#[test]
1879+
fn from_mut_no_copy() unsafe {
1880+
let x = [mut 1, 2, 3];
1881+
let addr = unsafe::to_ptr(x);
1882+
let x_imm = from_mut(x);
1883+
let addr_imm = unsafe::to_ptr(x_imm);
1884+
assert addr == addr_imm;
1885+
}
19521886
}
19531887

19541888
// Local Variables:

trunk/src/libstd/bitv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ init - If true then the bits are initialized to 1, otherwise 0
4949
*/
5050
fn create(nbits: uint, init: bool) -> t {
5151
let elt = if init { !0u } else { 0u };
52-
let storage = vec::init_elt_mut::<uint>(nbits / uint_bits + 1u, elt);
52+
let storage = vec::to_mut(vec::init_elt(nbits / uint_bits + 1u, elt));
5353
ret @{storage: storage, nbits: nbits};
5454
}
5555

@@ -117,7 +117,7 @@ Function: clone
117117
Makes a copy of a bitvector
118118
*/
119119
fn clone(v: t) -> t {
120-
let storage = vec::init_elt_mut::<uint>(v.nbits / uint_bits + 1u, 0u);
120+
let storage = vec::to_mut(vec::init_elt(v.nbits / uint_bits + 1u, 0u));
121121
let len = vec::len(v.storage);
122122
uint::range(0u, len) {|i| storage[i] = v.storage[i]; };
123123
ret @{storage: storage, nbits: v.nbits};

trunk/src/libstd/deque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn create<T: copy>() -> t<T> {
127127
mutable nelts: 0u,
128128
mutable lo: 0u,
129129
mutable hi: 0u,
130-
mutable elts: vec::init_elt_mut(initial_capacity, none)
130+
mutable elts: vec::to_mut(vec::init_elt(initial_capacity, none))
131131
};
132132
repr as t::<T>
133133
}

trunk/src/libstd/getopts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ err(fail_) - On failure. Use <fail_str> to get an error message.
212212
fn getopts(args: [str], opts: [opt]) -> result unsafe {
213213
let n_opts = vec::len::<opt>(opts);
214214
fn f(_x: uint) -> [optval] { ret []; }
215-
let vals = vec::init_fn_mut::<[optval]>(n_opts, f);
215+
let vals = vec::to_mut(vec::init_fn(n_opts, f));
216216
let free: [str] = [];
217217
let l = vec::len(args);
218218
let i = 0u;

trunk/src/libstd/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ mod chained {
243243
}
244244

245245
fn chains<K: copy, V: copy>(nchains: uint) -> [mutable chain<K,V>] {
246-
ret vec::init_elt_mut(nchains, absent);
246+
ret vec::to_mut(vec::init_elt(nchains, absent));
247247
}
248248

249249
fn foreach_entry<K: copy, V: copy>(chain0: chain<K,V>,

trunk/src/libstd/md4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn md4(msg: [u8]) -> {a: u32, b: u32, c: u32, d: u32} {
3030
}
3131

3232
let i = 0u, e = vec::len(msg);
33-
let x = vec::init_elt_mut(16u, 0u32);
33+
let x = vec::to_mut(vec::init_elt(16u, 0u32));
3434
while i < e {
3535
let aa = a, bb = b, cc = c, dd = d;
3636

trunk/src/libstd/rope.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ fn concat(v: [rope]) -> rope {
181181
//Copy `v` into a mutable vector
182182
let len = vec::len(v);
183183
if len == 0u { ret node::empty; }
184-
let ropes = vec::init_elt_mut(len, v[0]);
184+
let ropes = vec::to_mut(vec::init_elt(len, v[0]));
185185
uint::range(1u, len) {|i|
186186
ropes[i] = v[i];
187187
}
@@ -780,7 +780,7 @@ mod node {
780780
//Firstly, split `str` in slices of hint_max_leaf_char_len
781781
let leaves = uint::div_ceil(char_len, hint_max_leaf_char_len);
782782
//Number of leaves
783-
let nodes = vec::init_elt_mut(leaves, candidate);
783+
let nodes = vec::to_mut(vec::init_elt(leaves, candidate));
784784

785785
let i = 0u;
786786
let offset = byte_start;
@@ -893,7 +893,7 @@ mod node {
893893
}
894894

895895
fn serialize_node(node: @node) -> str unsafe {
896-
let buf = vec::init_elt_mut(byte_len(node), 0u8);
896+
let buf = vec::to_mut(vec::init_elt(byte_len(node), 0u8));
897897
let offset = 0u;//Current position in the buffer
898898
let it = leaf_iterator::start(node);
899899
while true {
@@ -1224,7 +1224,7 @@ mod node {
12241224
}
12251225

12261226
fn start(node: @node) -> t {
1227-
let stack = vec::init_elt_mut(height(node)+1u, node);
1227+
let stack = vec::to_mut(vec::init_elt(height(node)+1u, node));
12281228
ret {
12291229
stack: stack,
12301230
mutable stackpos: 0

trunk/src/libstd/sha1.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,13 @@ fn mk_sha1() -> sha1 {
274274
}
275275
}
276276
let st = {
277-
h: vec::init_elt_mut(digest_buf_len, 0u32),
277+
h: vec::to_mut(vec::init_elt(digest_buf_len, 0u32)),
278278
mutable len_low: 0u32,
279279
mutable len_high: 0u32,
280-
msg_block: vec::init_elt_mut(msg_block_len, 0u8),
280+
msg_block: vec::to_mut(vec::init_elt(msg_block_len, 0u8)),
281281
mutable msg_block_idx: 0u,
282282
mutable computed: false,
283-
work_buf: vec::init_elt_mut(work_buf_len, 0u32)
283+
work_buf: vec::to_mut(vec::init_elt(work_buf_len, 0u32))
284284
};
285285
let sh = st as sha1;
286286
sh.reset();

trunk/src/libstd/smallintmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn contains_key<T: copy>(m: smallintmap<T>, key: uint) -> bool {
7373
// FIXME: Are these really useful?
7474

7575
fn truncate<T: copy>(m: smallintmap<T>, len: uint) {
76-
m.v = vec::slice_mut::<option<T>>(m.v, 0u, len);
76+
m.v = vec::to_mut(vec::slice::<option<T>>(m.v, 0u, len));
7777
}
7878

7979
fn max_key<T>(m: smallintmap<T>) -> uint {

trunk/src/test/bench/shootout-fannkuchredux.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import vec;
66
fn fannkuch(n: int) -> int {
77
fn perm1init(i: uint) -> int { ret i as int; }
88

9-
let perm = vec::init_elt_mut(n as uint, 0);
10-
let perm1 = vec::init_fn_mut(n as uint, perm1init);
11-
let count = vec::init_elt_mut(n as uint, 0);
9+
let perm = vec::to_mut(vec::init_elt(n as uint, 0));
10+
let perm1 = vec::to_mut(vec::init_fn(n as uint, perm1init));
11+
let count = vec::to_mut(vec::init_elt(n as uint, 0));
1212
let f = 0;
1313
let i = 0;
1414
let k = 0;

trunk/src/test/bench/shootout-spectralnorm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn eval_At_times_u(u: [const float], Au: [mutable float]) {
3535
}
3636

3737
fn eval_AtA_times_u(u: [const float], AtAu: [mutable float]) {
38-
let v = vec::init_elt_mut(vec::len(u), 0.0);
38+
let v = vec::to_mut(vec::init_elt(vec::len(u), 0.0));
3939
eval_A_times_u(u, v);
4040
eval_At_times_u(v, AtAu);
4141
}
@@ -48,8 +48,8 @@ fn main(args: [str]) {
4848
1000u
4949
};
5050

51-
let u = vec::init_elt_mut(N, 1.0);
52-
let v = vec::init_elt_mut(N, 0.0);
51+
let u = vec::to_mut(vec::init_elt(N, 1.0));
52+
let v = vec::to_mut(vec::init_elt(N, 0.0));
5353
let i = 0u;
5454
while i < 10u {
5555
eval_AtA_times_u(u, v);

0 commit comments

Comments
 (0)