unify mrb_ary_new{,_elts,_from_values}; mrb_ary_from_values() is a winner

parent 7d470964
......@@ -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);
......
......@@ -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_new4(mrb_state *mrb, mrb_int n, const mrb_value *elts)
mrb_ary_new_from_values(mrb_state *mrb, mrb_int size, const mrb_value *vals)
{
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 */
{
......
......@@ -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_elts(mrb, m1+m2, stack);
regs[a] = mrb_ary_new_from_values(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_elts(mrb, argc-m1-o-m2, argv+m1+o);
regs[m1+o+1] = mrb_ary_new_from_values(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_elts(mrb, len - pre - post, ary->ptr+pre);
regs[a++] = mrb_ary_new_from_values(mrb, len - pre - post, ary->ptr+pre);
while (post--) {
regs[a++] = ary->ptr[len-post-1];
}
......
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