Skip to content

Commit 246a9a8

Browse files
committed
ary_concat: support self concatenation; fix #3302
1 parent 9fc62d2 commit 246a9a8

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/array.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,15 @@ mrb_ary_s_create(mrb_state *mrb, mrb_value self)
245245
}
246246

247247
static void
248-
ary_concat(mrb_state *mrb, struct RArray *a, mrb_value *ptr, mrb_int blen)
248+
ary_concat(mrb_state *mrb, struct RArray *a, struct RArray *a2)
249249
{
250-
mrb_int len = a->len + blen;
250+
mrb_int len = a->len + a2->len;
251251

252252
ary_modify(mrb, a);
253-
if (a->aux.capa < len) ary_expand_capa(mrb, a, len);
254-
array_copy(a->ptr+a->len, ptr, blen);
253+
if (a->aux.capa < len) {
254+
ary_expand_capa(mrb, a, len);
255+
}
256+
array_copy(a->ptr+a->len, a2->ptr, a2->len);
255257
mrb_write_barrier(mrb, (struct RBasic*)a);
256258
a->len = len;
257259
}
@@ -261,17 +263,16 @@ mrb_ary_concat(mrb_state *mrb, mrb_value self, mrb_value other)
261263
{
262264
struct RArray *a2 = mrb_ary_ptr(other);
263265

264-
ary_concat(mrb, mrb_ary_ptr(self), a2->ptr, a2->len);
266+
ary_concat(mrb, mrb_ary_ptr(self), a2);
265267
}
266268

267269
static mrb_value
268270
mrb_ary_concat_m(mrb_state *mrb, mrb_value self)
269271
{
270-
mrb_value *ptr;
271-
mrb_int blen;
272+
mrb_value ary;
272273

273-
mrb_get_args(mrb, "a", &ptr, &blen);
274-
ary_concat(mrb, mrb_ary_ptr(self), ptr, blen);
274+
mrb_get_args(mrb, "A", &ary);
275+
mrb_ary_concat(mrb, self, ary);
275276
return self;
276277
}
277278

0 commit comments

Comments
 (0)