Skip to content

Commit

Permalink
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
@@ -755,9 +755,34 @@ public static RubyModule getModuleFromScope(ThreadContext context, StaticScope s
return rubyClass;
}

@JIT
public static IRubyObject mergeKeywordArguments(ThreadContext context, IRubyObject restKwarg, IRubyObject explcitKwarg) {
return ((RubyHash) TypeConverter.checkHashType(context.runtime, restKwarg)).merge(context, explcitKwarg, Block.NULL_BLOCK);
@JIT @Interp
public static IRubyObject mergeKeywordArguments(ThreadContext context, IRubyObject restKwarg, IRubyObject explicitKwarg) {
RubyHash hash = (RubyHash) TypeConverter.checkHashType(context.runtime, restKwarg).dup();

hash.modify();
final RubyHash otherHash = explicitKwarg.convertToHash();

if (otherHash.empty_p().isTrue()) return hash;

otherHash.visitAll(context, new KwargMergeVisitor(hash), Block.NULL_BLOCK);

return hash;
}

private static class KwargMergeVisitor extends RubyHash.VisitorWithState<Block> {
final RubyHash target;

KwargMergeVisitor(RubyHash target) {
this.target = target;
}

@Override
public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, Block block) {
// All kwargs keys must be symbols.
TypeConverter.checkType(context, key, context.runtime.getSymbol());

target.op_aset(context, key, value);
}
}

@JIT

0 comments on commit 1ec8b39

Please sign in to comment.