Skip to content

Commit bd5b4c0

Browse files
committed
---
yaml --- r: 14249 b: refs/heads/try c: e5cc919 h: refs/heads/master i: 14247: bf2d555 v: v3
1 parent 9983a74 commit bd5b4c0

File tree

3 files changed

+13
-108
lines changed

3 files changed

+13
-108
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: fde719f635955b1c3d76639062410262fd0df351
5+
refs/heads/try: e5cc9193f8b91f8d21621b452e45d0e37c200757
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libcore/iter.rs

Lines changed: 2 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -65,43 +65,18 @@ fn flat_map<A,B,IA:iterable<A>,IB:iterable<B>>(
6565
}
6666
}
6767

68-
fn foldl<A,B,IA:iterable<A>>(self: IA, +b0: B, blk: fn(-B, A) -> B) -> B {
69-
let b <- b0;
68+
fn foldl<A,B:copy,IA:iterable<A>>(self: IA, b0: B, blk: fn(B, A) -> B) -> B {
69+
let b = b0;
7070
self.iter {|a|
7171
b = blk(b, a);
7272
}
7373
ret b;
7474
}
7575

76-
fn foldr<A:copy,B,IA:iterable<A>>(
77-
self: IA, +b0: B, blk: fn(A, -B) -> B) -> B {
78-
79-
let b <- b0;
80-
reverse(self) {|a|
81-
b = blk(a, b);
82-
}
83-
ret b;
84-
}
85-
8676
fn to_list<A:copy,IA:iterable<A>>(self: IA) -> [A] {
8777
foldl::<A,[A],IA>(self, [], {|r, a| r + [a]})
8878
}
8979

90-
// FIXME: This could be made more efficient with an riterable interface
91-
fn reverse<A:copy,IA:iterable<A>>(self: IA, blk: fn(A)) {
92-
vec::riter(to_list(self), blk)
93-
}
94-
95-
fn count<A,IA:iterable<A>>(self: IA, x: A) -> uint {
96-
foldl(self, 0u) {|count, value|
97-
if value == x {
98-
count + 1u
99-
} else {
100-
count
101-
}
102-
}
103-
}
104-
10580
fn repeat(times: uint, blk: fn()) {
10681
let i = 0u;
10782
while i < times {
@@ -110,35 +85,6 @@ fn repeat(times: uint, blk: fn()) {
11085
}
11186
}
11287

113-
fn min<A:copy,IA:iterable<A>>(self: IA) -> A {
114-
alt foldl::<A,option<A>,IA>(self, none) {|a, b|
115-
alt a {
116-
some(a_) if a_ < b {
117-
// FIXME: Not sure if this is successfully optimized to a move
118-
a
119-
}
120-
_ { some(b) }
121-
}
122-
} {
123-
some(val) { val }
124-
none { fail "min called on empty iterator" }
125-
}
126-
}
127-
128-
fn max<A:copy,IA:iterable<A>>(self: IA) -> A {
129-
alt foldl::<A,option<A>,IA>(self, none) {|a, b|
130-
alt a {
131-
some(a_) if a_ > b {
132-
// FIXME: Not sure if this is successfully optimized to a move
133-
a
134-
}
135-
_ { some(b) }
136-
}
137-
} {
138-
some(val) { val }
139-
none { fail "max called on empty iterator" }
140-
}
141-
}
14288

14389
#[test]
14490
fn test_enumerate() {
@@ -222,45 +168,4 @@ fn test_repeat() {
222168
assert c == [0u, 1u, 4u, 9u, 16u];
223169
}
224170

225-
#[test]
226-
fn test_min() {
227-
assert min([5, 4, 1, 2, 3]) == 1;
228-
}
229-
230-
#[test]
231-
#[should_fail]
232-
#[ignore(cfg(target_os = "win32"))]
233-
fn test_min_empty() {
234-
min::<int, [int]>([]);
235-
}
236-
237-
#[test]
238-
fn test_max() {
239-
assert max([1, 2, 4, 2, 3]) == 4;
240-
}
241-
242-
#[test]
243-
#[should_fail]
244-
#[ignore(cfg(target_os = "win32"))]
245-
fn test_max_empty() {
246-
max::<int, [int]>([]);
247-
}
248171

249-
#[test]
250-
fn test_reverse() {
251-
assert to_list(bind reverse([1, 2, 3], _)) == [3, 2, 1];
252-
}
253-
254-
#[test]
255-
fn test_count() {
256-
assert count([1, 2, 1, 2, 1], 1) == 3u;
257-
}
258-
259-
#[test]
260-
fn test_foldr() {
261-
fn sub(&&a: int, -b: int) -> int {
262-
a - b
263-
}
264-
let sum = foldr([1, 2, 3, 4], 0, sub);
265-
assert sum == -2;
266-
}

branches/try/src/libcore/str.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,16 @@ Function: from_cstr_len
213213
Create a Rust string from a C string of the given length
214214
*/
215215
unsafe fn from_cstr_len(cstr: sbuf, len: uint) -> str {
216-
let res = [];
217-
let start = cstr;
218-
let curr = start;
219-
let i = 0u;
220-
while i < len {
221-
vec::push(res, *curr);
222-
i += 1u;
223-
curr = ptr::offset(start, i);
224-
}
225-
ret from_bytes(res);
216+
let buf: [u8] = [];
217+
vec::reserve(buf, len + 1u);
218+
vec::as_buf(buf) {|b| ptr::memcpy(b, cstr, len); }
219+
vec::unsafe::set_len(buf, len);
220+
buf += [0u8];
221+
222+
assert is_utf8(buf);
223+
let s: str = ::unsafe::reinterpret_cast(buf);
224+
::unsafe::leak(buf);
225+
ret s;
226226
}
227227

228228
/*

0 commit comments

Comments
 (0)