refactoring around mrb_hash_new

This commit is contained in:
Yukihiro Matsumoto
2012-06-02 21:42:52 +09:00
parent d9dfbb044a
commit de133c3715
2 changed files with 8 additions and 6 deletions
+2 -2
View File
@@ -20,8 +20,8 @@ struct RHash {
#define mrb_hash_ptr(v) ((struct RHash*)((v).value.p))
#define mrb_hash_value(p) mrb_obj_value((void*)(p))
mrb_value mrb_hash_new_capa(mrb_state*, size_t);
mrb_value mrb_hash_new(mrb_state *mrb, int capa);
mrb_value mrb_hash_new_capa(mrb_state*, int);
mrb_value mrb_hash_new(mrb_state *mrb);
void mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val);
mrb_value mrb_hash_get(mrb_state *mrb, mrb_value hash, mrb_value key);
+6 -4
View File
@@ -81,21 +81,23 @@ mrb_gc_free_ht(mrb_state *mrb, struct RHash *hash)
mrb_value
mrb_hash_new_capa(mrb_state *mrb, size_t capa)
mrb_hash_new_capa(mrb_state *mrb, int capa)
{
struct RHash *h;
h = (struct RHash*)mrb_obj_alloc(mrb, MRB_TT_HASH, mrb->hash_class);
h->ht = kh_init(ht, mrb);
kh_resize(ht, h->ht, capa);
if (capa > 0) {
kh_resize(ht, h->ht, capa);
}
h->iv = 0;
return mrb_obj_value(h);
}
mrb_value
mrb_hash_new(mrb_state *mrb, int capa)
mrb_hash_new(mrb_state *mrb)
{
return mrb_hash_new_capa(mrb, capa);
return mrb_hash_new_capa(mrb, 0);
}
mrb_value