diff options
| author | Yukihiro Matsumoto <[email protected]> | 2012-06-02 21:42:52 +0900 |
|---|---|---|
| committer | Yukihiro Matsumoto <[email protected]> | 2012-06-02 21:42:52 +0900 |
| commit | de133c37154fc2d433961ab900411b3c8cd23bef (patch) | |
| tree | 4ebe486fe76c9d063c293cdbe1afd360e11686f4 | |
| parent | d9dfbb044afa59413afbd62b3d59cbe3f1fee342 (diff) | |
| download | mruby-de133c37154fc2d433961ab900411b3c8cd23bef.tar.gz mruby-de133c37154fc2d433961ab900411b3c8cd23bef.zip | |
refactoring around mrb_hash_new
| -rw-r--r-- | include/mruby/hash.h | 4 | ||||
| -rw-r--r-- | src/hash.c | 10 |
2 files changed, 8 insertions, 6 deletions
diff --git a/include/mruby/hash.h b/include/mruby/hash.h index 6cb3d8ec8..0e002052c 100644 --- a/include/mruby/hash.h +++ b/include/mruby/hash.h @@ -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); diff --git a/src/hash.c b/src/hash.c index a06becd91..6c19919e5 100644 --- a/src/hash.c +++ b/src/hash.c @@ -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 |
