Skip to content

Commit 21f1fe0

Browse files
committed
---
yaml --- r: 10640 b: refs/heads/snap-stage3 c: 0e5cfd9 h: refs/heads/master v: v3
1 parent 5cef5a1 commit 21f1fe0

File tree

20 files changed

+173
-248
lines changed

20 files changed

+173
-248
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: f8fa0a243788e6b1028d254958cd19c6f10034fa
4+
refs/heads/snap-stage3: 0e5cfd9f339c78384ef3fbcb4d230fa0bb363d54
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/src/libcore/dvec.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ impl extensions<A:copy> for dvec<A> {
137137
#[doc = "Append a single item to the end of the list"]
138138
fn push(t: A) {
139139
self.swap { |v|
140-
let mut v <- v; v += [t]; v // more efficient than v + [t]
140+
let mut v <- v;
141+
vec::push(v, t);
142+
v
141143
}
142144
}
143145

@@ -170,7 +172,7 @@ impl extensions<A:copy> for dvec<A> {
170172
vec::reserve(v, new_len);
171173
let mut i = from_idx;
172174
while i < to_idx {
173-
v += [ts[i]];
175+
vec::push(v, ts[i]);
174176
i += 1u;
175177
}
176178
v

branches/snap-stage3/src/libcore/ptr.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export is_null;
1010
export is_not_null;
1111
export memcpy;
1212
export memmove;
13+
export memset;
1314
export buf_len;
1415
export position;
1516
export extensions;
@@ -23,6 +24,8 @@ native mod libc_ {
2324
fn memcpy(dest: *c_void, src: *c_void, n: libc::size_t) -> *c_void;
2425
#[rust_stack]
2526
fn memmove(dest: *c_void, src: *c_void, n: libc::size_t) -> *c_void;
27+
#[rust_stack]
28+
fn memset(dest: *c_void, c: libc::c_int, len: libc::size_t) -> *c_void;
2629
}
2730

2831
#[abi = "rust-intrinsic"]
@@ -108,6 +111,12 @@ unsafe fn memmove<T>(dst: *T, src: *T, count: uint) {
108111
libc_::memmove(dst as *c_void, src as *c_void, n as size_t);
109112
}
110113

114+
#[inline(always)]
115+
unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
116+
let n = count * sys::size_of::<T>();
117+
libc_::memset(dst as *c_void, c as libc::c_int, n as size_t);
118+
}
119+
111120
#[doc = "Extension methods for pointers"]
112121
impl extensions<T> for *T {
113122
#[doc = "Returns true if the pointer is equal to the null pointer."]

branches/snap-stage3/src/libcore/str.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,8 +1743,9 @@ mod unsafe {
17431743
Does not verify that the vector contains valid UTF-8.
17441744
"]
17451745
unsafe fn from_bytes(v: [const u8]) -> str unsafe {
1746-
let vcopy = v + [0u8];
1747-
ret ::unsafe::transmute(vcopy);
1746+
let mut vcopy : [u8] = ::unsafe::transmute(copy v);
1747+
vec::push(vcopy, 0u8);
1748+
::unsafe::transmute(vcopy)
17481749
}
17491750

17501751
#[doc = "

branches/snap-stage3/src/libcore/vec.rs

Lines changed: 90 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import option::{some, none};
44
import ptr::addr_of;
55
import libc::size_t;
66

7+
export append;
78
export init_op;
89
export is_empty;
910
export is_not_empty;
@@ -187,7 +188,9 @@ pure fn from_elem<T: copy>(n_elts: uint, t: T) -> [T] {
187188
let mut v = [];
188189
unchecked{reserve(v, n_elts)}
189190
let mut i: uint = 0u;
190-
while i < n_elts { v += [t]; i += 1u; }
191+
unsafe { // because push is impure
192+
while i < n_elts { push(v, t); i += 1u; }
193+
}
191194
ret v;
192195
}
193196

@@ -372,11 +375,8 @@ fn shift<T: copy>(&v: [T]) -> T {
372375
}
373376

374377
#[doc = "Prepend an element to a vector"]
375-
fn unshift<T: copy>(&v: [const T], +t: T) {
376-
// n.b.---for most callers, using unshift() ought not to type check, but
377-
// it does. It's because the type system is unaware of the mutability of
378-
// `v` and so allows the vector to be covariant.
379-
v = [const t] + v;
378+
fn unshift<T: copy>(&v: [T], +t: T) {
379+
v = [t] + v;
380380
}
381381

382382
#[doc = "Remove the last element from a vector and return it"]
@@ -390,12 +390,69 @@ fn pop<T>(&v: [const T]) -> T unsafe {
390390
}
391391

392392
#[doc = "Append an element to a vector"]
393+
#[inline(always)]
393394
fn push<T>(&v: [const T], +initval: T) {
394-
v += [initval];
395+
let ln = v.len();
396+
unsafe {
397+
reserve_at_least(v, ln + 1u);
398+
unsafe::set_len(v, ln + 1u);
399+
let p = ptr::mut_addr_of(v[ln]);
400+
401+
// FIXME: for performance, try replacing the memmove and <- with a
402+
// memset and unsafe::forget.
403+
ptr::memset(p, 0, 1u); // needed to stop drop glue from running on
404+
// garbage data.
405+
*p = initval;
406+
}
395407
}
396408

409+
#[inline(always)]
410+
fn push_all<T: copy>(&v: [const T], rhs: [const T]/&) {
411+
for uint::range(0u, rhs.len()) {|i|
412+
push(v, rhs[i]);
413+
}
414+
}
397415

398416
// Appending
417+
#[inline(always)]
418+
pure fn append<T: copy>(lhs: [T]/&, rhs: [const T]/&) -> [T] {
419+
let mut v = [];
420+
let mut i = 0u;
421+
while i < lhs.len() {
422+
unsafe { // This is impure, but it appears pure to the caller.
423+
push(v, lhs[i]);
424+
}
425+
i += 1u;
426+
}
427+
i = 0u;
428+
while i < rhs.len() {
429+
unsafe { // This is impure, but it appears pure to the caller.
430+
push(v, rhs[i]);
431+
}
432+
i += 1u;
433+
}
434+
ret v;
435+
}
436+
437+
#[inline(always)]
438+
pure fn append_mut<T: copy>(lhs: [mut T]/&, rhs: [const T]/&) -> [mut T] {
439+
let mut v = [mut];
440+
let mut i = 0u;
441+
while i < lhs.len() {
442+
unsafe { // This is impure, but it appears pure to the caller.
443+
push(v, lhs[i]);
444+
}
445+
i += 1u;
446+
}
447+
i = 0u;
448+
while i < rhs.len() {
449+
unsafe { // This is impure, but it appears pure to the caller.
450+
push(v, rhs[i]);
451+
}
452+
i += 1u;
453+
}
454+
ret v;
455+
}
399456

400457
#[doc = "
401458
Expands a vector in place, initializing the new elements to a given value
@@ -409,7 +466,8 @@ Expands a vector in place, initializing the new elements to a given value
409466
fn grow<T: copy>(&v: [const T], n: uint, initval: T) {
410467
reserve_at_least(v, len(v) + n);
411468
let mut i: uint = 0u;
412-
while i < n { v += [initval]; i += 1u; }
469+
470+
while i < n { push(v, initval); i += 1u; }
413471
}
414472

415473
#[doc = "
@@ -428,7 +486,7 @@ Function `init_op` is called `n` times with the values [0..`n`)
428486
fn grow_fn<T>(&v: [const T], n: uint, op: init_op<T>) {
429487
reserve_at_least(v, len(v) + n);
430488
let mut i: uint = 0u;
431-
while i < n { v += [op(i)]; i += 1u; }
489+
while i < n { push(v, op(i)); i += 1u; }
432490
}
433491

434492
#[doc = "
@@ -453,7 +511,7 @@ Apply a function to each element of a vector and return the results
453511
pure fn map<T, U>(v: [T]/&, f: fn(T) -> U) -> [U] {
454512
let mut result = [];
455513
unchecked{reserve(result, len(v));}
456-
for each(v) {|elem| result += [f(elem)]; }
514+
for each(v) {|elem| unsafe { push(result, f(elem)); } }
457515
ret result;
458516
}
459517

@@ -486,7 +544,10 @@ pure fn map2<T: copy, U: copy, V>(v0: [T]/&, v1: [U]/&,
486544
if v0_len != len(v1) { fail; }
487545
let mut u: [V] = [];
488546
let mut i = 0u;
489-
while i < v0_len { u += [f(copy v0[i], copy v1[i])]; i += 1u; }
547+
while i < v0_len {
548+
unsafe { push(u, f(copy v0[i], copy v1[i])) };
549+
i += 1u;
550+
}
490551
ret u;
491552
}
492553

@@ -502,7 +563,7 @@ pure fn filter_map<T, U: copy>(v: [T]/&, f: fn(T) -> option<U>)
502563
for each(v) {|elem|
503564
alt f(elem) {
504565
none {/* no-op */ }
505-
some(result_elem) { result += [result_elem]; }
566+
some(result_elem) { unsafe { push(result, result_elem); } }
506567
}
507568
}
508569
ret result;
@@ -518,7 +579,7 @@ only those elements for which `f` returned true.
518579
pure fn filter<T: copy>(v: [T]/&, f: fn(T) -> bool) -> [T] {
519580
let mut result = [];
520581
for each(v) {|elem|
521-
if f(elem) { result += [elem]; }
582+
if f(elem) { unsafe { push(result, elem); } }
522583
}
523584
ret result;
524585
}
@@ -530,7 +591,7 @@ Flattens a vector of vectors of T into a single vector of T.
530591
"]
531592
pure fn concat<T: copy>(v: [[T]]/&) -> [T] {
532593
let mut r = [];
533-
for each(v) {|inner| r += inner; }
594+
for each(v) {|inner| unsafe { push_all(r, inner); } }
534595
ret r;
535596
}
536597

@@ -541,7 +602,7 @@ pure fn connect<T: copy>(v: [[T]]/&, sep: T) -> [T] {
541602
let mut r: [T] = [];
542603
let mut first = true;
543604
for each(v) {|inner|
544-
if first { first = false; } else { r += [sep]; }
605+
if first { first = false; } else { unsafe { push(r, sep); } }
545606
r += inner;
546607
}
547608
ret r;
@@ -1025,6 +1086,20 @@ pure fn unpack_mut_slice<T,U>(s: [mut T]/&,
10251086
f(buf, len / sys::size_of::<T>())
10261087
}
10271088

1089+
impl extensions<T: copy> for [T] {
1090+
#[inline(always)]
1091+
pure fn +(rhs: [T]/&) -> [T] {
1092+
append(self, rhs)
1093+
}
1094+
}
1095+
1096+
impl extensions<T: copy> for [mut T] {
1097+
#[inline(always)]
1098+
pure fn +(rhs: [mut T]/&) -> [mut T] {
1099+
append_mut(self, rhs)
1100+
}
1101+
}
1102+
10281103
#[doc = "Extension methods for vectors"]
10291104
impl extensions/&<T> for [const T]/& {
10301105
#[doc = "Returns true if a vector contains no elements"]

branches/snap-stage3/src/libstd/deque.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ fn create<T: copy>() -> t<T> {
3333
let nalloc = uint::next_power_of_two(nelts + 1u);
3434
while i < nalloc {
3535
if i < nelts {
36-
rv += [mut elts[(lo + i) % nelts]];
37-
} else { rv += [mut none]; }
36+
vec::push(rv, elts[(lo + i) % nelts]);
37+
} else { vec::push(rv, none); }
3838
i += 1u;
3939
}
4040

branches/snap-stage3/src/libstd/rope.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ mod node {
864864
loop {
865865
alt (leaf_iterator::next(it)) {
866866
option::none { break; }
867-
option::some(x) { forest += [mut @leaf(x)]; }
867+
option::some(x) { vec::push(forest, @leaf(x)); }
868868
}
869869
}
870870
//2. Rebuild tree from forest

branches/snap-stage3/src/libsyntax/ast_util.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,17 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
480480
vfn(id);
481481
},
482482

483-
visit_fn: fn@(fk: visit::fn_kind, d: fn_decl,
484-
_b: blk, _sp: span, id: node_id) {
483+
visit_fn: fn@(fk: visit::fn_kind, d: ast::fn_decl,
484+
_b: ast::blk, _sp: span, id: ast::node_id) {
485485
vfn(id);
486486

487487
alt fk {
488-
visit::fk_ctor(_, tps, self_id, parent_id) |
488+
visit::fk_ctor(nm, tps, self_id, parent_id) {
489+
vec::iter(tps) {|tp| vfn(tp.id)}
490+
vfn(id);
491+
vfn(self_id);
492+
vfn(parent_id.node);
493+
}
489494
visit::fk_dtor(tps, self_id, parent_id) {
490495
vec::iter(tps) {|tp| vfn(tp.id)}
491496
vfn(id);
@@ -500,7 +505,11 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
500505
vfn(m.self_id);
501506
vec::iter(tps) {|tp| vfn(tp.id)}
502507
}
503-
visit::fk_anon(*) | visit::fk_fn_block(*) {
508+
visit::fk_anon(_, capture_clause)
509+
| visit::fk_fn_block(capture_clause) {
510+
for vec::each(*capture_clause) {|clause|
511+
vfn(clause.id);
512+
}
504513
}
505514
}
506515

branches/snap-stage3/src/libsyntax/parse/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl parser_common for parser {
159159
else { self.expect(t); } }
160160
_ { }
161161
}
162-
v += [f(self)];
162+
vec::push(v, f(self));
163163
}
164164

165165
ret v;
@@ -202,7 +202,7 @@ impl parser_common for parser {
202202
_ { }
203203
}
204204
if sep.trailing_sep_allowed && self.token == ket { break; }
205-
v += [f(self)];
205+
vec::push(v, f(self));
206206
}
207207
ret v;
208208
}

0 commit comments

Comments
 (0)