reduce hash creation by using update method

parent 287f317f
......@@ -12,4 +12,5 @@ class Hash
end
alias each_pair each
alias update merge!
end
......@@ -183,6 +183,11 @@ class Hash
}
h
end
def __update(h)
h.each{|k,v| self[k] = v}
self
end
end
##
......
......@@ -1513,7 +1513,7 @@ codegen(codegen_scope *s, node *tree, int val)
genop(s, MKOP_ABC(OP_HASH, cursp(), cursp(), len));
if (update) {
pop();
genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "merge")), 1));
genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "__update")), 1));
}
push();
update = TRUE;
......@@ -1525,7 +1525,7 @@ codegen(codegen_scope *s, node *tree, int val)
genop(s, MKOP_ABC(OP_HASH, cursp(), cursp(), len));
if (update) {
pop();
genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "merge")), 1));
genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "__update")), 1));
}
push();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment