1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* array.c (ary_memfill): added.

* array.c (rb_ary_initialize): use ary_memfill().
* array.c (rb_ary_fill): ditto.
* array.c (rb_ary_slice_bang): use RARRAY_RAWPTR() because
  this code creates no new references.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42105 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2013-07-22 04:00:12 +00:00
parent 4132ac3762
commit 8eb0a3cd50
2 changed files with 23 additions and 8 deletions

View file

@ -1,3 +1,14 @@
Mon Jul 22 12:58:18 2013 Koichi Sasada <ko1@atdot.net>
* array.c (ary_memfill): added.
* array.c (rb_ary_initialize): use ary_memfill().
* array.c (rb_ary_fill): ditto.
* array.c (rb_ary_slice_bang): use RARRAY_RAWPTR() because
this code creates no new references.
Mon Jul 22 10:09:46 2013 Koichi Sasada <ko1@atdot.net> Mon Jul 22 10:09:46 2013 Koichi Sasada <ko1@atdot.net>
* gc.c (gc_slot_sweep): need to add empty RVALUE as freeobj. * gc.c (gc_slot_sweep): need to add empty RVALUE as freeobj.

20
array.c
View file

@ -101,6 +101,15 @@ memfill(register VALUE *mem, register long size, register VALUE val)
} }
} }
static void
ary_memfill(VALUE ary, long beg, long size, VALUE val)
{
RARRAY_PTR_USE(ary, ptr, {
memfill(ptr + beg, size, val);
OBJ_WRITTEN(ary, Qundef, val);
});
}
static void static void
ary_memcpy(VALUE ary, long beg, long argc, const VALUE *argv) ary_memcpy(VALUE ary, long beg, long argc, const VALUE *argv)
{ {
@ -787,10 +796,7 @@ rb_ary_initialize(int argc, VALUE *argv, VALUE ary)
} }
} }
else { else {
RARRAY_PTR_USE(ary, ptr, { ary_memfill(ary, 0, len, val);
memfill((VALUE *)ptr, len, val);
});
OBJ_WRITTEN(ary, Qundef, val);
ARY_SET_LEN(ary, len); ARY_SET_LEN(ary, len);
} }
return ary; return ary;
@ -2999,7 +3005,7 @@ rb_ary_slice_bang(int argc, VALUE *argv, VALUE ary)
len = orig_len - pos; len = orig_len - pos;
} }
if (len == 0) return rb_ary_new2(0); if (len == 0) return rb_ary_new2(0);
arg2 = rb_ary_new4(len, RARRAY_PTR(ary)+pos); arg2 = rb_ary_new4(len, RARRAY_RAWPTR(ary)+pos);
RBASIC_SET_CLASS(arg2, rb_obj_class(ary)); RBASIC_SET_CLASS(arg2, rb_obj_class(ary));
rb_ary_splice(ary, pos, len, Qundef); rb_ary_splice(ary, pos, len, Qundef);
return arg2; return arg2;
@ -3372,7 +3378,6 @@ rb_ary_fill(int argc, VALUE *argv, VALUE ary)
{ {
VALUE item, arg1, arg2; VALUE item, arg1, arg2;
long beg = 0, end = 0, len = 0; long beg = 0, end = 0, len = 0;
VALUE *p;
int block_p = FALSE; int block_p = FALSE;
if (rb_block_given_p()) { if (rb_block_given_p()) {
@ -3429,8 +3434,7 @@ rb_ary_fill(int argc, VALUE *argv, VALUE ary)
} }
} }
else { else {
p = RARRAY_PTR(ary) + beg; ary_memfill(ary, beg, len, item);
memfill(p, len, item);
} }
return ary; return ary;
} }