Skip to content

Commit 9b27091

Browse files
committed
---
yaml --- r: 31740 b: refs/heads/dist-snap c: 79b5f68 h: refs/heads/master v: v3
1 parent 8bf671a commit 9b27091

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: f110e8f21c707cb4bbb5e54b45f4458987920322
10+
refs/heads/dist-snap: 79b5f681765ae9d295f4ca8056a90dbbafbe1d9d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/src/libcore/at_vec.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ pure fn build<A>(builder: fn(push: pure fn(+A))) -> @[A] {
7878
build_sized(4, builder)
7979
}
8080

81+
// Appending
82+
#[inline(always)]
83+
pure fn append<T: copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
84+
do build_sized(lhs.len() + rhs.len()) |push| {
85+
for vec::each(lhs) |x| { push(x); }
86+
for uint::range(0, rhs.len()) |i| { push(rhs[i]); }
87+
}
88+
}
89+
90+
8191
/// Apply a function to each element of a vector and return the results
8292
pure fn map<T, U>(v: &[T], f: fn(T) -> U) -> @[U] {
8393
do build_sized(v.len()) |push| {
@@ -113,6 +123,21 @@ pure fn from_elem<T: copy>(n_elts: uint, t: T) -> @[T] {
113123
}
114124
}
115125

126+
impl extensions<T: copy> of vec_concat<T> for @[T] {
127+
#[inline(always)]
128+
pure fn +(rhs: &[const T]) -> @[T] {
129+
append(self, rhs)
130+
}
131+
}
132+
133+
#[cfg(notest)]
134+
impl extensions<T: copy> of add<&[const T],@[T]> for @[T] {
135+
#[inline(always)]
136+
pure fn add(rhs: &[const T]) -> @[T] {
137+
append(self, rhs)
138+
}
139+
}
140+
116141

117142
mod unsafe {
118143
type vec_repr = vec::unsafe::vec_repr;
@@ -213,4 +238,10 @@ fn test() {
213238
assert seq_range(10, 15) == @[10, 11, 12, 13, 14];
214239
assert from_fn(5, |x| x+1) == @[1, 2, 3, 4, 5];
215240
assert from_elem(5, 3.14) == @[3.14, 3.14, 3.14, 3.14, 3.14];
216-
}
241+
}
242+
243+
#[test]
244+
fn append_test() {
245+
assert @[1,2,3] + @[4,5,6] == @[1,2,3,4,5,6];
246+
}
247+

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ pure fn riteri<T>(v: &[T], f: fn(uint, T)) {
12111211
* The total number of permutations produced is `len(v)!`. If `v` contains
12121212
* repeated elements, then some permutations are repeated.
12131213
*/
1214-
pure fn permute<T: copy>(v: &[T], put: fn(~[T])) {
1214+
pure fn permute<T: copy>(v: &[const T], put: fn(~[T])) {
12151215
let ln = len(v);
12161216
if ln == 0u {
12171217
put(~[]);
@@ -1221,7 +1221,7 @@ pure fn permute<T: copy>(v: &[T], put: fn(~[T])) {
12211221
let elt = v[i];
12221222
let mut rest = slice(v, 0u, i);
12231223
unchecked {
1224-
push_all(rest, view(v, i+1u, ln));
1224+
push_all(rest, const_view(v, i+1u, ln));
12251225
permute(rest, |permutation| {
12261226
put(append(~[elt], permutation))
12271227
})

0 commit comments

Comments
 (0)