Unverified Commit ea71f116 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #4188 from dearblue/mrb_hash_size

Add `mrb_hash_size()` function
parents ec812c64 62dd4d89
......@@ -165,6 +165,19 @@ MRB_API mrb_value mrb_hash_values(mrb_state *mrb, mrb_value hash);
*/
MRB_API mrb_value mrb_hash_clear(mrb_state *mrb, mrb_value hash);
/*
* Get hash size.
*
* Equivalent to:
*
* hash.size
*
* @param mrb The mruby state reference.
* @param hash The target hash.
* @return The hash size.
*/
MRB_API mrb_int mrb_hash_size(mrb_state *mrb, mrb_value hash);
/*
* Copies the hash.
*
......
......@@ -1133,6 +1133,15 @@ mrb_hash_aset(mrb_state *mrb, mrb_value self)
return val;
}
MRB_API mrb_int
mrb_hash_size(mrb_state *mrb, mrb_value hash)
{
htable *t = RHASH_TBL(hash);
if (!t) return 0;
return t->size;
}
/* 15.2.13.4.20 */
/* 15.2.13.4.25 */
/*
......@@ -1150,10 +1159,7 @@ mrb_hash_aset(mrb_state *mrb, mrb_value self)
static mrb_value
mrb_hash_size_m(mrb_state *mrb, mrb_value self)
{
htable *t = RHASH_TBL(self);
if (!t) return mrb_fixnum_value(0);
return mrb_fixnum_value(t->size);
return mrb_fixnum_value(mrb_hash_size(mrb, self));
}
MRB_API mrb_bool
......
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