mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* struct.c (rb_struct_initialize_m): avoid unnecessary array
allocation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
017769b199
commit
d87e2d811a
2 changed files with 18 additions and 8 deletions
|
@ -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.
|
||||
|
|
21
struct.c
21
struct.c
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue