ruby-changes:10826
From: nobu <ko1@a...>
Date: Wed, 18 Feb 2009 14:33:50 +0900 (JST)
Subject: [ruby-changes:10826] Ruby:r22395 (trunk): * array.c (rb_ary_resurrect), string.c (rb_str_resurrect): new
nobu 2009-02-18 14:33:36 +0900 (Wed, 18 Feb 2009) New Revision: 22395 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=22395 Log: * array.c (rb_ary_resurrect), string.c (rb_str_resurrect): new functions based on [ruby-dev:37983] * insns.def (putstring, duparray): use rb_{ary,str}_resurrect(). * iseq.c (iseq_data_to_ary): needs to result TS_VALUE. Modified files: trunk/ChangeLog trunk/array.c trunk/insns.def trunk/iseq.c trunk/string.c trunk/vm_core.h Index: array.c =================================================================== --- array.c (revision 22394) +++ array.c (revision 22395) @@ -1469,6 +1469,12 @@ return dup; } +VALUE +rb_ary_resurrect(VALUE ary) +{ + return rb_ary_new4(RARRAY_LEN(ary), RARRAY_PTR(ary)); +} + extern VALUE rb_output_fs; static VALUE Index: insns.def =================================================================== --- insns.def (revision 22394) +++ insns.def (revision 22395) @@ -373,7 +373,7 @@ () (VALUE val) { - val = rb_str_replace(rb_str_new(0, 0), str); + val = rb_str_resurrect(str); } /** @@ -460,7 +460,7 @@ () (VALUE val) { - val = rb_ary_replace(rb_ary_new2(0), ary); + val = rb_ary_resurrect(ary); } /** Index: ChangeLog =================================================================== --- ChangeLog (revision 22394) +++ ChangeLog (revision 22395) @@ -1,3 +1,12 @@ +Wed Feb 18 14:33:35 2009 Nobuyoshi Nakada <nobu@r...> + + * array.c (rb_ary_resurrect), string.c (rb_str_resurrect): new + functions based on [ruby-dev:37983] + + * insns.def (putstring, duparray): use rb_{ary,str}_resurrect(). + + * iseq.c (iseq_data_to_ary): needs to result TS_VALUE. + Wed Feb 18 12:35:31 2009 Nobuyoshi Nakada <nobu@r...> * file.c (rb_file_s_extname): fix for spaces before extention. Index: vm_core.h =================================================================== --- vm_core.h (revision 22394) +++ vm_core.h (revision 22395) @@ -599,6 +599,9 @@ #define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack] +VALUE rb_str_resurrect(VALUE str); +VALUE rb_ary_resurrect(VALUE ary); + /* for thread */ #if RUBY_VM_THREAD_MODEL == 2 Index: iseq.c =================================================================== --- iseq.c (revision 22394) +++ iseq.c (revision 22395) @@ -23,6 +23,22 @@ #define hidden_obj_p(obj) (!SPECIAL_CONST_P(obj) && !RBASIC(obj)->klass) +static inline VALUE +obj_resurrect(VALUE obj) +{ + if (hidden_obj_p(obj)) { + switch (BUILTIN_TYPE(obj)) { + case T_STRING: + obj = rb_str_resurrect(obj); + break; + case T_ARRAY: + obj = rb_ary_resurrect(obj); + break; + } + } + return obj; +} + static void compile_data_free(struct iseq_compile_data *compile_data) { @@ -701,16 +717,7 @@ op = ID2SYM(op); case TS_VALUE: /* VALUE */ - if (hidden_obj_p(op)) { - switch (BUILTIN_TYPE(op)) { - case T_STRING: - op = rb_str_replace(rb_str_new(0, 0), op); - break; - case T_ARRAY: - op = rb_ary_replace(rb_ary_new2(0), op); - break; - } - } + op = obj_resurrect(op); ret = rb_inspect(op); if (CLASS_OF(op) == rb_cISeq) { rb_ary_push(child, op); @@ -1141,7 +1148,7 @@ rb_ary_push(ary, INT2FIX(*seq)); break; case TS_VALUE: - rb_ary_push(ary, *seq); + rb_ary_push(ary, obj_resurrect(*seq)); break; case TS_ISEQ: { Index: string.c =================================================================== --- string.c (revision 22394) +++ string.c (revision 22395) @@ -828,6 +828,11 @@ return str_duplicate(rb_obj_class(str), str); } +VALUE +rb_str_resurrect(VALUE str) +{ + return rb_str_replace(str_alloc(rb_cString), str); +} /* * call-seq: -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/