ruby-changes:11904
From: matz <ko1@a...>
Date: Mon, 25 May 2009 09:43:41 +0900 (JST)
Subject: [ruby-changes:11904] Ruby:r23565 (trunk): * string.c (rb_str_hash): avoid calling rb_enc_str_asciionly_p().
matz 2009-05-25 09:43:23 +0900 (Mon, 25 May 2009) New Revision: 23565 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23565 Log: * string.c (rb_str_hash): avoid calling rb_enc_str_asciionly_p(). * string.c (rb_str_replace): avoid redundant calling rb_str_new4(). * string.c (str_replace): factor out replacement from rb_str_replace() without type check nor discarding the destination contents. Modified files: trunk/ChangeLog trunk/string.c Index: ChangeLog =================================================================== --- ChangeLog (revision 23564) +++ ChangeLog (revision 23565) @@ -1,3 +1,13 @@ +Mon May 25 09:34:09 2009 Yukihiro Matsumoto <matz@r...> + + * string.c (rb_str_hash): avoid calling rb_enc_str_asciionly_p(). + + * string.c (rb_str_replace): avoid redundant calling rb_str_new4(). + + * string.c (str_replace): factor out replacement from + rb_str_replace() without type check nor discarding the + destination contents. + Mon May 25 08:06:52 2009 Nobuyoshi Nakada <nobu@r...> * string.c (rb_str_partition): should use the converted result. a Index: string.c =================================================================== --- string.c (revision 23564) +++ string.c (revision 23565) @@ -815,10 +815,36 @@ } static VALUE +str_replace(VALUE str, VALUE str2) +{ + long len; + + len = RSTRING_LEN(str2); + if (STR_ASSOC_P(str2)) { + str2 = rb_str_new4(str2); + } + if (STR_SHARED_P(str2)) { + STR_SET_NOEMBED(str); + RSTRING(str)->as.heap.len = len; + RSTRING(str)->as.heap.ptr = RSTRING_PTR(str2); + FL_SET(str, ELTS_SHARED); + FL_UNSET(str, STR_ASSOC); + RSTRING(str)->as.heap.aux.shared = RSTRING(str2)->as.heap.aux.shared; + } + else { + str_replace_shared(str, str2); + } + + OBJ_INFECT(str, str2); + rb_enc_cr_str_exact_copy(str, str2); + return str; +} + +static VALUE str_duplicate(VALUE klass, VALUE str) { VALUE dup = str_alloc(klass); - rb_str_replace(dup, str); + str_replace(dup, str); return dup; } @@ -831,7 +857,7 @@ VALUE rb_str_resurrect(VALUE str) { - return rb_str_replace(str_alloc(rb_cString), str); + return str_replace(str_alloc(rb_cString), str); } /* @@ -2179,8 +2205,8 @@ rb_str_hash(VALUE str) { int e = ENCODING_GET(str); - if (e) { - if (rb_enc_str_asciionly_p(str)) e = 0; + if (e && rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT) { + e = 0; } return (int)rb_memhash((const void *)RSTRING_PTR(str), RSTRING_LEN(str)) ^ e; } @@ -3840,30 +3866,11 @@ VALUE rb_str_replace(VALUE str, VALUE str2) { - long len; if (str == str2) return str; StringValue(str2); - len = RSTRING_LEN(str2); - if (STR_ASSOC_P(str2)) { - str2 = rb_str_new4(str2); - } str_discard(str); - if (STR_SHARED_P(str2)) { - STR_SET_NOEMBED(str); - RSTRING(str)->as.heap.len = len; - RSTRING(str)->as.heap.ptr = RSTRING_PTR(str2); - FL_SET(str, ELTS_SHARED); - FL_UNSET(str, STR_ASSOC); - RSTRING(str)->as.heap.aux.shared = RSTRING(str2)->as.heap.aux.shared; - } - else { - str_replace_shared(str, rb_str_new4(str2)); - } - - OBJ_INFECT(str, str2); - rb_enc_cr_str_exact_copy(str, str2); - return str; + return str_replace(str, str2); } /* -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/