Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Wroclove.rb - JRuby vs. Rubinius

Wroclove.rb - JRuby vs. Rubinius

Fighting for the Rubinius side

Dirkjan Bussink

March 14, 2012
Tweet

More Decks by Dirkjan Bussink

Other Decks in Technology

Transcript

  1. @JRubyMethod(name = {"collect", "map"}, compat = CompatVersion.RUBY1_8) public static IRubyObject

    collect(ThreadContext context, IRubyObject self, final Block block) { final Ruby runtime = context.getRuntime(); final RubyArray result = runtime.newArray(); if (block.isGiven()) { callEach(runtime, context, self, block.arity(), new BlockCallback() { public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) { IRubyObject larg = checkArgs(runtime, largs); IRubyObject value = block.yield(ctx, larg); synchronized (result) { result.append(value); } return runtime.getNil(); } }); } else { callEach(runtime, context, self, Arity.ONE_ARGUMENT, new AppendBlockCallback(runtime, result)); } return result; }
  2. def collect if block_given? ary = [] each do |*o|

    ary << yield(*o) end ary else to_enum :collect end end
  3. > (x . xs) = [1, 2, 3] [1, 2,

    3] > x 1 > xs [2, 3]