From 4675f860849c5d064d1279b2eff324a271024254 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 26 Feb 2012 22:08:41 -0800 Subject: [PATCH] rustdoc: Do less copying in util::parmap --- src/rustdoc/util.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/rustdoc/util.rs b/src/rustdoc/util.rs index b864cad99835..dbc143bcc872 100644 --- a/src/rustdoc/util.rs +++ b/src/rustdoc/util.rs @@ -1,13 +1,17 @@ export parmap; -fn parmap(v: [T], f: fn~(T) -> U) -> [U] { +fn parmap(v: [T], f: fn~(T) -> U) -> [U] unsafe { let futures = vec::map(v) {|elt| - future::spawn {|| - f(elt) + let po = comm::port(); + let ch = comm::chan(po); + let addr = ptr::addr_of(elt); + task::spawn {|| + comm::send(ch, f(*addr)); } + po }; vec::map(futures) {|future| - future::get(future) + comm::recv(future) } }