From 812b61acca8db165665ded69cdb2a7379da8ad52 Mon Sep 17 00:00:00 2001 From: yugui Date: Sun, 22 Feb 2009 12:49:14 +0000 Subject: merges r22255 from trunk into ruby_1_9_1. * compile.c (compile_array_, defined_expr, iseq_compile_each): hide and freeze internal literal objects, to prevent from modifying. [ruby-dev:37959] * iseq.c (insn_operand_intern): copy internal literal objects. * insns.def (putstring, duparray): ditto. * string.c (rb_str_replace): exported. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@22532 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index c3b47fb47..432fdc4c7 100644 --- a/string.c +++ b/string.c @@ -815,14 +815,18 @@ rb_obj_as_string(VALUE obj) return str; } -static VALUE rb_str_replace(VALUE, VALUE); +static VALUE +str_duplicate(VALUE klass, VALUE str) +{ + VALUE dup = str_alloc(klass); + rb_str_replace(dup, str); + return dup; +} VALUE rb_str_dup(VALUE str) { - VALUE dup = str_alloc(rb_obj_class(str)); - rb_str_replace(dup, str); - return dup; + return str_duplicate(rb_obj_class(str), str); } @@ -3675,7 +3679,7 @@ rb_str_gsub(int argc, VALUE *argv, VALUE str) * s.replace "world" #=> "world" */ -static VALUE +VALUE rb_str_replace(VALUE str, VALUE str2) { long len; @@ -3977,9 +3981,7 @@ static VALUE rb_str_to_s(VALUE str) { if (rb_obj_class(str) != rb_cString) { - VALUE dup = str_alloc(rb_cString); - rb_str_replace(dup, str); - return dup; + return str_duplicate(rb_cString, str); } return str; } -- cgit