Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
ea71f116
Unverified
Commit
ea71f116
authored
Dec 17, 2018
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Dec 17, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4188 from dearblue/mrb_hash_size
Add `mrb_hash_size()` function
parents
ec812c64
62dd4d89
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
4 deletions
+23
-4
include/mruby/hash.h
include/mruby/hash.h
+13
-0
src/hash.c
src/hash.c
+10
-4
No files found.
include/mruby/hash.h
View file @
ea71f116
...
...
@@ -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.
*
...
...
src/hash.c
View file @
ea71f116
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment