ruby-changes:42537
From: nobu <ko1@a...>
Date: Sat, 16 Apr 2016 09:03:09 +0900 (JST)
Subject: [ruby-changes:42537] nobu:r54611 (trunk): struct.c: struct_make_members_list
nobu 2016-04-16 09:59:42 +0900 (Sat, 16 Apr 2016) New Revision: 54611 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54611 Log: struct.c: struct_make_members_list * struct.c (struct_make_members_list): extract making member name list from char* va_list, with creating symbols without intermediate IDs. Modified files: trunk/ChangeLog trunk/struct.c Index: ChangeLog =================================================================== --- ChangeLog (revision 54610) +++ ChangeLog (revision 54611) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Apr 16 09:59:40 2016 Nobuyoshi Nakada <nobu@r...> + + * struct.c (struct_make_members_list): extract making member name + list from char* va_list, with creating symbols without + intermediate IDs. + Sat Apr 16 01:33:27 2016 CHIKANAGA Tomoyuki <nagachika@r...> * tool/redmine-backporter.rb: sort revisions. Index: struct.c =================================================================== --- struct.c (revision 54610) +++ struct.c (revision 54611) @@ -331,6 +331,20 @@ rb_struct_alloc_noinit(VALUE klass) https://github.com/ruby/ruby/blob/trunk/struct.c#L331 } static VALUE +struct_make_members_list(va_list ar) +{ + char *mem; + VALUE ary = rb_ary_tmp_new(0); + + while ((mem = va_arg(ar, char*)) != 0) { + VALUE sym = rb_sym_intern_ascii_cstr(mem); + rb_ary_push(ary, sym); + } + OBJ_FREEZE_RAW(ary); + return ary; +} + +static VALUE struct_define_without_accessor(VALUE outer, const char *class_name, VALUE super, rb_alloc_func_t alloc, VALUE members) { VALUE klass; @@ -364,15 +378,10 @@ rb_struct_define_without_accessor_under( https://github.com/ruby/ruby/blob/trunk/struct.c#L378 { va_list ar; VALUE members; - char *name; - members = rb_ary_tmp_new(0); va_start(ar, alloc); - while ((name = va_arg(ar, char*)) != NULL) { - rb_ary_push(members, ID2SYM(rb_intern(name))); - } + members = struct_make_members_list(ar); va_end(ar); - OBJ_FREEZE_RAW(members); return struct_define_without_accessor(outer, class_name, super, alloc, members); } @@ -382,15 +391,10 @@ rb_struct_define_without_accessor(const https://github.com/ruby/ruby/blob/trunk/struct.c#L391 { va_list ar; VALUE members; - char *name; - members = rb_ary_tmp_new(0); va_start(ar, alloc); - while ((name = va_arg(ar, char*)) != NULL) { - rb_ary_push(members, ID2SYM(rb_intern(name))); - } + members = struct_make_members_list(ar); va_end(ar); - OBJ_FREEZE_RAW(members); return struct_define_without_accessor(0, class_name, super, alloc, members); } @@ -400,17 +404,10 @@ rb_struct_define(const char *name, ...) https://github.com/ruby/ruby/blob/trunk/struct.c#L404 { va_list ar; VALUE st, ary; - char *mem; - - ary = rb_ary_tmp_new(0); va_start(ar, name); - while ((mem = va_arg(ar, char*)) != 0) { - ID slot = rb_intern(mem); - rb_ary_push(ary, ID2SYM(slot)); - } + ary = struct_make_members_list(ar); va_end(ar); - OBJ_FREEZE_RAW(ary); if (!name) st = anonymous_struct(rb_cStruct); else st = new_struct(rb_str_new2(name), rb_cStruct); @@ -422,17 +419,10 @@ rb_struct_define_under(VALUE outer, cons https://github.com/ruby/ruby/blob/trunk/struct.c#L419 { va_list ar; VALUE ary; - char *mem; - - ary = rb_ary_tmp_new(0); va_start(ar, name); - while ((mem = va_arg(ar, char*)) != 0) { - ID slot = rb_intern(mem); - rb_ary_push(ary, ID2SYM(slot)); - } + ary = struct_make_members_list(ar); va_end(ar); - OBJ_FREEZE_RAW(ary); return setup_struct(rb_define_class_under(outer, name, rb_cStruct), ary); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/