Commit ba8a8e75 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #1702 from cremno/hash-hash-ext-changes

hash / hash-ext: various small changes
parents 69eaaa14 4ffea85b
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "mruby.h" #include "mruby.h"
#include "mruby/array.h" #include "mruby/array.h"
#include "mruby/hash.h" #include "mruby/hash.h"
#include "mruby/khash.h"
/* /*
* call-seq: * call-seq:
...@@ -20,27 +19,18 @@ ...@@ -20,27 +19,18 @@
* h.values_at("cow", "cat") #=> ["bovine", "feline"] * 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 static mrb_value
hash_values_at(mrb_state *mrb, mrb_value hash) hash_values_at(mrb_state *mrb, mrb_value hash)
{ {
mrb_value *argv; mrb_value *argv, result;
int argc; int argc, i;
mrb_get_args(mrb, "*", &argv, &argc); mrb_get_args(mrb, "*", &argv, &argc);
result = mrb_ary_new_capa(mrb, argc);
return mrb_hash_values_at(mrb, argc, argv, hash); for (i = 0; i < argc; i++) {
mrb_ary_push(mrb, result, mrb_hash_get(mrb, hash, argv[i]));
}
return result;
} }
void void
...@@ -49,7 +39,6 @@ mrb_mruby_hash_ext_gem_init(mrb_state *mrb) ...@@ -49,7 +39,6 @@ mrb_mruby_hash_ext_gem_init(mrb_state *mrb)
struct RClass *h; struct RClass *h;
h = mrb->hash_class; 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());
} }
......
This diff is collapsed.
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