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
13d9631e
Commit
13d9631e
authored
Jul 06, 2014
by
take_cheeze
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new API `mrb_ary_resize`(mruby implementation of `rb_ary_resize`).
parent
5c50bcd2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
include/mruby/array.h
include/mruby/array.h
+1
-0
src/array.c
src/array.c
+22
-0
No files found.
include/mruby/array.h
View file @
13d9631e
...
...
@@ -54,6 +54,7 @@ mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset);
mrb_value
mrb_ary_shift
(
mrb_state
*
mrb
,
mrb_value
self
);
mrb_value
mrb_ary_clear
(
mrb_state
*
mrb
,
mrb_value
self
);
mrb_value
mrb_ary_join
(
mrb_state
*
mrb
,
mrb_value
ary
,
mrb_value
sep
);
mrb_value
mrb_ary_resize
(
mrb_state
*
mrb
,
mrb_value
ary
,
mrb_int
len
);
static
inline
mrb_int
mrb_ary_len
(
mrb_state
*
mrb
,
mrb_value
ary
)
...
...
src/array.c
View file @
13d9631e
...
...
@@ -231,6 +231,28 @@ ary_shrink_capa(mrb_state *mrb, struct RArray *a)
}
}
mrb_value
mrb_ary_resize
(
mrb_state
*
mrb
,
mrb_value
ary
,
mrb_int
new_len
)
{
mrb_int
old_len
;
struct
RArray
*
a
=
mrb_ary_ptr
(
ary
);
ary_modify
(
mrb
,
a
);
old_len
=
RARRAY_LEN
(
ary
);
if
(
old_len
!=
new_len
)
{
a
->
len
=
new_len
;
if
(
new_len
<
old_len
)
{
ary_shrink_capa
(
mrb
,
a
);
}
else
{
ary_expand_capa
(
mrb
,
a
,
new_len
);
ary_fill_with_nil
(
a
->
ptr
+
old_len
,
new_len
-
old_len
);
}
}
return
ary
;
}
static
mrb_value
mrb_ary_s_create
(
mrb_state
*
mrb
,
mrb_value
self
)
{
...
...
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