Skip to content

Commit

Permalink
merges r20164 from trunk into ruby_1_9_1.
Browse files Browse the repository at this point in the history
* struct.c (rb_struct_initialize_m): avoid unnecessary array
  allocation.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@20202 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
yugui committed Nov 11, 2008
1 parent 60b278b commit eaceb0f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Sun Nov 9 13:04:52 2008 Yukihiro Matsumoto <matz@ruby-lang.org>

* struct.c (rb_struct_initialize_m): avoid unnecessary array
allocation.

Sun Nov 9 04:10:19 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>

* vm_dump.c (control_frame_dump): suppresses finished method name.
Expand Down
21 changes: 13 additions & 8 deletions struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,25 +352,30 @@ num_members(VALUE klass)
/*
*/

VALUE
rb_struct_initialize(VALUE self, VALUE values)
static VALUE
rb_struct_initialize_m(int argc, VALUE *argv, VALUE self)
{
VALUE klass = rb_obj_class(self);
long n;

rb_struct_modify(self);
n = num_members(klass);
if (n < RARRAY_LEN(values)) {
if (n < argc) {
rb_raise(rb_eArgError, "struct size differs");
}
MEMCPY(RSTRUCT_PTR(self), RARRAY_PTR(values), VALUE, RARRAY_LEN(values));
if (n > RARRAY_LEN(values)) {
rb_mem_clear(RSTRUCT_PTR(self)+RARRAY_LEN(values),
n-RARRAY_LEN(values));
MEMCPY(RSTRUCT_PTR(self), argv, VALUE, argc);
if (n > argc) {
rb_mem_clear(RSTRUCT_PTR(self)+argc, n-argc);
}
return Qnil;
}

VALUE
rb_struct_initialize(VALUE self, VALUE values)
{
return rb_struct_initialize_m(RARRAY_LEN(values), RARRAY_PTR(values), self);
}

static VALUE
struct_alloc(VALUE klass)
{
Expand Down Expand Up @@ -879,7 +884,7 @@ Init_Struct(void)
rb_undef_alloc_func(rb_cStruct);
rb_define_singleton_method(rb_cStruct, "new", rb_struct_s_def, -1);

rb_define_method(rb_cStruct, "initialize", rb_struct_initialize, -2);
rb_define_method(rb_cStruct, "initialize", rb_struct_initialize_m, -1);
rb_define_method(rb_cStruct, "initialize_copy", rb_struct_init_copy, 1);

rb_define_method(rb_cStruct, "==", rb_struct_equal, 1);
Expand Down

0 comments on commit eaceb0f

Please sign in to comment.