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
cdd41a33
Commit
cdd41a33
authored
Mar 08, 2013
by
Yukihiro Matz Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unify mrb_ary_new{,_elts,_from_values}; mrb_ary_from_values() is a winner
parent
7d470964
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
33 deletions
+13
-33
include/mruby/array.h
include/mruby/array.h
+4
-3
src/array.c
src/array.c
+6
-27
src/vm.c
src/vm.c
+3
-3
No files found.
include/mruby/array.h
View file @
cdd41a33
...
...
@@ -38,12 +38,14 @@ struct RArray {
void
mrb_ary_decref
(
mrb_state
*
,
mrb_shared_array
*
);
mrb_value
mrb_ary_new_capa
(
mrb_state
*
,
mrb_int
);
mrb_value
mrb_ary_new
(
mrb_state
*
mrb
);
mrb_value
mrb_ary_new_elts
(
mrb_state
*
mrb
,
mrb_int
n
,
const
mrb_value
*
elts
);
mrb_value
mrb_ary_new_from_values
(
mrb_state
*
mrb
,
mrb_int
size
,
const
mrb_value
*
vals
);
/* compatibility macros - soon to be removed */
#define mrb_ary_new_elts(mrb,size,vals) mrb_ary_new_from_values(mrb,size,vals)
#define mrb_ary_new4(mrb,size,vals) mrb_ary_new_from_values(mrb,size,vals)
void
mrb_ary_concat
(
mrb_state
*
,
mrb_value
,
mrb_value
);
mrb_value
mrb_ary_splat
(
mrb_state
*
,
mrb_value
);
void
mrb_ary_push
(
mrb_state
*
,
mrb_value
,
mrb_value
);
mrb_value
mrb_ary_pop
(
mrb_state
*
mrb
,
mrb_value
ary
);
mrb_value
mrb_ary_new_from_values
(
mrb_state
*
mrb
,
mrb_int
size
,
mrb_value
*
vals
);
mrb_value
mrb_ary_aget
(
mrb_state
*
mrb
,
mrb_value
self
);
mrb_value
mrb_ary_ref
(
mrb_state
*
mrb
,
mrb_value
ary
,
mrb_int
n
);
void
mrb_ary_set
(
mrb_state
*
mrb
,
mrb_value
ary
,
mrb_int
n
,
mrb_value
val
);
...
...
@@ -51,7 +53,6 @@ mrb_int mrb_ary_len(mrb_state *mrb, mrb_value ary);
void
mrb_ary_replace
(
mrb_state
*
mrb
,
mrb_value
a
,
mrb_value
b
);
mrb_value
mrb_check_array_type
(
mrb_state
*
mrb
,
mrb_value
self
);
mrb_value
mrb_ary_unshift
(
mrb_state
*
mrb
,
mrb_value
self
,
mrb_value
item
);
mrb_value
mrb_ary_new4
(
mrb_state
*
mrb
,
mrb_int
n
,
const
mrb_value
*
elts
);
mrb_value
mrb_assoc_new
(
mrb_state
*
mrb
,
mrb_value
car
,
mrb_value
cdr
);
mrb_value
mrb_ary_entry
(
mrb_value
ary
,
mrb_int
offset
);
mrb_value
mrb_ary_shift
(
mrb_state
*
mrb
,
mrb_value
self
);
...
...
src/array.c
View file @
cdd41a33
...
...
@@ -89,21 +89,6 @@ array_copy(mrb_value *dst, const mrb_value *src, size_t size)
}
}
mrb_value
mrb_ary_new_from_values
(
mrb_state
*
mrb
,
mrb_int
size
,
mrb_value
*
vals
)
{
mrb_value
ary
;
struct
RArray
*
a
;
ary
=
mrb_ary_new_capa
(
mrb
,
size
);
a
=
mrb_ary_ptr
(
ary
);
array_copy
(
a
->
ptr
,
vals
,
size
);
a
->
len
=
size
;
return
ary
;
}
mrb_value
mrb_assoc_new
(
mrb_state
*
mrb
,
mrb_value
car
,
mrb_value
cdr
)
{
...
...
@@ -433,25 +418,19 @@ mrb_ary_reverse(mrb_state *mrb, mrb_value self)
}
mrb_value
mrb_ary_new
4
(
mrb_state
*
mrb
,
mrb_int
n
,
const
mrb_value
*
elt
s
)
mrb_ary_new
_from_values
(
mrb_state
*
mrb
,
mrb_int
size
,
const
mrb_value
*
val
s
)
{
mrb_value
ary
;
struct
RArray
*
a
;
ary
=
mrb_ary_new_capa
(
mrb
,
n
);
if
(
n
>
0
&&
elts
)
{
array_copy
(
RARRAY_PTR
(
ary
),
elts
,
n
);
RARRAY_LEN
(
ary
)
=
n
;
}
ary
=
mrb_ary_new_capa
(
mrb
,
size
);
a
=
mrb_ary_ptr
(
ary
);
array_copy
(
a
->
ptr
,
vals
,
size
);
a
->
len
=
size
;
return
ary
;
}
mrb_value
mrb_ary_new_elts
(
mrb_state
*
mrb
,
mrb_int
n
,
const
mrb_value
*
elts
)
{
return
mrb_ary_new4
(
mrb
,
n
,
elts
);
}
void
mrb_ary_push
(
mrb_state
*
mrb
,
mrb_value
ary
,
mrb_value
elem
)
/* mrb_ary_push */
{
...
...
src/vm.c
View file @
cdd41a33
...
...
@@ -1061,7 +1061,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
stack
=
e
->
stack
+
1
;
}
if
(
r
==
0
)
{
regs
[
a
]
=
mrb_ary_new_
elt
s
(
mrb
,
m1
+
m2
,
stack
);
regs
[
a
]
=
mrb_ary_new_
from_value
s
(
mrb
,
m1
+
m2
,
stack
);
}
else
{
mrb_value
*
pp
=
NULL
;
...
...
@@ -1149,7 +1149,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
memmove
(
&
regs
[
1
],
argv
,
sizeof
(
mrb_value
)
*
(
m1
+
o
));
/* m1 + o */
}
if
(
r
)
{
/* r */
regs
[
m1
+
o
+
1
]
=
mrb_ary_new_
elt
s
(
mrb
,
argc
-
m1
-
o
-
m2
,
argv
+
m1
+
o
);
regs
[
m1
+
o
+
1
]
=
mrb_ary_new_
from_value
s
(
mrb
,
argc
-
m1
-
o
-
m2
,
argv
+
m1
+
o
);
}
if
(
m2
)
{
memmove
(
&
regs
[
m1
+
o
+
r
+
1
],
&
argv
[
argc
-
m2
],
sizeof
(
mrb_value
)
*
m2
);
...
...
@@ -1731,7 +1731,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
int
i
;
if
(
len
>
pre
+
post
)
{
regs
[
a
++
]
=
mrb_ary_new_
elt
s
(
mrb
,
len
-
pre
-
post
,
ary
->
ptr
+
pre
);
regs
[
a
++
]
=
mrb_ary_new_
from_value
s
(
mrb
,
len
-
pre
-
post
,
ary
->
ptr
+
pre
);
while
(
post
--
)
{
regs
[
a
++
]
=
ary
->
ptr
[
len
-
post
-
1
];
}
...
...
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