diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-03-21 09:31:44 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-03-21 09:31:44 +0900 |
| commit | 2c44f96e78832dd42e35a9cae6e90dccaf5c2178 (patch) | |
| tree | 52121a3a9f0845c25a40aeaa975068805d9d599f | |
| parent | 287f317f051894b53f43c659d89e75a46f2203ad (diff) | |
| download | mruby-2c44f96e78832dd42e35a9cae6e90dccaf5c2178.tar.gz mruby-2c44f96e78832dd42e35a9cae6e90dccaf5c2178.zip | |
reduce hash creation by using update method
| -rw-r--r-- | mrbgems/mruby-hash-ext/mrblib/hash.rb | 1 | ||||
| -rw-r--r-- | mrblib/hash.rb | 5 | ||||
| -rw-r--r-- | src/codegen.c | 4 |
3 files changed, 8 insertions, 2 deletions
diff --git a/mrbgems/mruby-hash-ext/mrblib/hash.rb b/mrbgems/mruby-hash-ext/mrblib/hash.rb index 3d512b574..723a0b907 100644 --- a/mrbgems/mruby-hash-ext/mrblib/hash.rb +++ b/mrbgems/mruby-hash-ext/mrblib/hash.rb @@ -12,4 +12,5 @@ class Hash end alias each_pair each + alias update merge! end diff --git a/mrblib/hash.rb b/mrblib/hash.rb index c15f770f7..20dd67091 100644 --- a/mrblib/hash.rb +++ b/mrblib/hash.rb @@ -183,6 +183,11 @@ class Hash } h end + + def __update(h) + h.each{|k,v| self[k] = v} + self + end end ## diff --git a/src/codegen.c b/src/codegen.c index 9b14d1530..2efad00bc 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -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(); } |
