summaryrefslogtreecommitdiff
path: root/struct.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-11 11:01:57 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-11 11:01:57 +0000
commiteaceb0fb5a681302c3629175222c3af36c662e60 (patch)
tree42a0f22e426abcdcd761f5eb65e31b24c9dae620 /struct.c
parent60b278bb8b1f860d9a9f6ca39f62ef1795f0da60 (diff)
merges r20164 from trunk into ruby_1_9_1.
* 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
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/struct.c b/struct.c
index add6bfa03d..0cc836123f 100644
--- a/struct.c
+++ b/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);