From cdd41a33de55369bd89bdf916d6ab419bd93c2b5 Mon Sep 17 00:00:00 2001 From: Yukihiro Matz Matsumoto Date: Fri, 8 Mar 2013 05:18:33 +0900 Subject: unify mrb_ary_new{,_elts,_from_values}; mrb_ary_from_values() is a winner --- src/array.c | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) (limited to 'src/array.c') diff --git a/src/array.c b/src/array.c index b8cd436f0..97f76f8da 100644 --- a/src/array.c +++ b/src/array.c @@ -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 */ { -- cgit v1.2.3