mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
refactoring around mrb_hash_new
This commit is contained in:
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user