diff options
Diffstat (limited to 'mrbgems/mruby-hash-ext/src/hash-ext.c')
| -rw-r--r-- | mrbgems/mruby-hash-ext/src/hash-ext.c | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/mrbgems/mruby-hash-ext/src/hash-ext.c b/mrbgems/mruby-hash-ext/src/hash-ext.c index 94518924e..937a7fddd 100644 --- a/mrbgems/mruby-hash-ext/src/hash-ext.c +++ b/mrbgems/mruby-hash-ext/src/hash-ext.c @@ -6,11 +6,7 @@ #include "mruby.h" #include "mruby/array.h" -#include "mruby/class.h" #include "mruby/hash.h" -#include "mruby/khash.h" -#include "mruby/string.h" -#include "mruby/variable.h" /* * call-seq: @@ -23,27 +19,20 @@ * h.values_at("cow", "cat") #=> ["bovine", "feline"] */ -mrb_value -mrb_hash_values_at(mrb_state *mrb, int argc, mrb_value *argv, mrb_value hash) -{ - mrb_value result = mrb_ary_new_capa(mrb, argc); - long i; - - for (i=0; i<argc; i++) { - mrb_ary_push(mrb, result, mrb_hash_get(mrb, hash, argv[i])); - } - return result; -} - static mrb_value hash_values_at(mrb_state *mrb, mrb_value hash) { - mrb_value *argv; - int argc; + mrb_value *argv, result; + int argc, i, ai; mrb_get_args(mrb, "*", &argv, &argc); - - return mrb_hash_values_at(mrb, argc, argv, hash); + result = mrb_ary_new_capa(mrb, argc); + ai = mrb_gc_arena_save(mrb); + for (i = 0; i < argc; i++) { + mrb_ary_push(mrb, result, mrb_hash_get(mrb, hash, argv[i])); + mrb_gc_arena_restore(mrb, ai); + } + return result; } void @@ -52,8 +41,7 @@ mrb_mruby_hash_ext_gem_init(mrb_state *mrb) struct RClass *h; h = mrb->hash_class; - - mrb_define_method(mrb, h, "values_at", hash_values_at, MRB_ARGS_ANY()); + mrb_define_method(mrb, h, "values_at", hash_values_at, MRB_ARGS_ANY()); } void |
