reduce hash creation by using update method

parent 287f317f
...@@ -12,4 +12,5 @@ class Hash ...@@ -12,4 +12,5 @@ class Hash
end end
alias each_pair each alias each_pair each
alias update merge!
end end
...@@ -183,6 +183,11 @@ class Hash ...@@ -183,6 +183,11 @@ class Hash
} }
h h
end end
def __update(h)
h.each{|k,v| self[k] = v}
self
end
end end
## ##
......
...@@ -1513,7 +1513,7 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -1513,7 +1513,7 @@ codegen(codegen_scope *s, node *tree, int val)
genop(s, MKOP_ABC(OP_HASH, cursp(), cursp(), len)); genop(s, MKOP_ABC(OP_HASH, cursp(), cursp(), len));
if (update) { if (update) {
pop(); 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(); push();
update = TRUE; update = TRUE;
...@@ -1525,7 +1525,7 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -1525,7 +1525,7 @@ codegen(codegen_scope *s, node *tree, int val)
genop(s, MKOP_ABC(OP_HASH, cursp(), cursp(), len)); genop(s, MKOP_ABC(OP_HASH, cursp(), cursp(), len));
if (update) { if (update) {
pop(); 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(); 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