[macruby-changes] [3542] MacRuby/trunk/lib/dispatch/enumerable.rb
source_changes at macosforge.org
source_changes at macosforge.org
Mon Feb 15 17:30:25 PST 2010
Revision: 3542
http://trac.macosforge.org/projects/ruby/changeset/3542
Author: ernest.prabhakar at gmail.com
Date: 2010-02-15 17:30:24 -0800 (Mon, 15 Feb 2010)
Log Message:
-----------
Refactored Dispatch Enumerable to use dispatch_apply via p_times
Modified Paths:
--------------
MacRuby/trunk/lib/dispatch/enumerable.rb
Modified: MacRuby/trunk/lib/dispatch/enumerable.rb
===================================================================
--- MacRuby/trunk/lib/dispatch/enumerable.rb 2010-02-16 01:30:15 UTC (rev 3541)
+++ MacRuby/trunk/lib/dispatch/enumerable.rb 2010-02-16 01:30:24 UTC (rev 3542)
@@ -24,22 +24,17 @@
end
module Enumerable
+
# Parallel +each+
- def p_each(&block)
- grp = Dispatch::Group.new
- self.each do |obj|
- Dispatch.group(grp) { block.call(obj) }
- end
- grp.wait
+ def p_each(stride=1, priority=nil, &block)
+ ary = self.to_a
+ size.p_times(stride, priority) { |i| block.call(ary[i]) }
end
- # Parallel +each_with_index+
- def p_each_with_index(&block)
- grp = Dispatch::Group.new
- self.each_with_index do |obj, i|
- Dispatch.group(grp) { block.call(obj, i) }
- end
- grp.wait
+ # Parallel +each+
+ def p_each_with_index(stride=1, priority=nil, &block)
+ ary = self.to_a
+ size.p_times(stride, priority) { |i| block.call(ary[i], i) }
end
# Parallel +collect+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100215/6136241a/attachment.html>
More information about the macruby-changes
mailing list