mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
reduce hash creation by using update method
This commit is contained in:
@@ -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
|
||||
|
||||
##
|
||||
|
||||
+2
-2
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user