Skip to content

Commit d79fbba

Browse files
committedMar 30, 2014
auto merge of #13203 : Kimundi/rust/de-map-vec3, r=cmr
They required unnecessary temporaries, are replaced with iterators, and would conflict with a possible future `Iterable` trait.
·
1.88.00.10
2 parents 86890b9 + c356e3b commit d79fbba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+278
-325
lines changed
 

‎src/doc/tutorial.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,10 @@ access local variables in the enclosing scope.
17641764
17651765
~~~~
17661766
let mut max = 0;
1767-
[1, 2, 3].map(|x| if *x > max { max = *x });
1767+
let f = |x: int| if x > max { max = x };
1768+
for x in [1, 2, 3].iter() {
1769+
f(*x);
1770+
}
17681771
~~~~
17691772
17701773
Stack closures are very efficient because their environment is

‎src/libnative/io/process.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ fn with_argv<T>(prog: &str, args: &[~str], cb: proc:(**libc::c_char) -> T) -> T
597597
// Next, convert each of the byte strings into a pointer. This is
598598
// technically unsafe as the caller could leak these pointers out of our
599599
// scope.
600-
let mut ptrs = tmps.map(|tmp| tmp.with_ref(|buf| buf));
600+
let mut ptrs: Vec<_> = tmps.iter().map(|tmp| tmp.with_ref(|buf| buf)).collect();
601601

602602
// Finally, make sure we add a null pointer.
603603
ptrs.push(ptr::null());
@@ -622,7 +622,9 @@ fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: proc:(*c_void) -> T) -> T {
622622
}
623623

624624
// Once again, this is unsafe.
625-
let mut ptrs = tmps.map(|tmp| tmp.with_ref(|buf| buf));
625+
let mut ptrs: Vec<*libc::c_char> = tmps.iter()
626+
.map(|tmp| tmp.with_ref(|buf| buf))
627+
.collect();
626628
ptrs.push(ptr::null());
627629

628630
cb(ptrs.as_ptr() as *c_void)

0 commit comments

Comments
 (0)
Please sign in to comment.