ruby-changes:10800
From: nobu <ko1@a...>
Date: Tue, 17 Feb 2009 12:51:19 +0900 (JST)
Subject: [ruby-changes:10800] Ruby:r22368 (trunk, ruby_1_8): * string.c (rb_str_shared_replace): no need for
nobu 2009-02-17 12:50:59 +0900 (Tue, 17 Feb 2009) New Revision: 22368 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=22368 Log: * string.c (rb_str_shared_replace): no need for str_make_independent. Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/string.c branches/ruby_1_8/version.h trunk/ChangeLog trunk/string.c Index: ChangeLog =================================================================== --- ChangeLog (revision 22367) +++ ChangeLog (revision 22368) @@ -1,3 +1,8 @@ +Tue Feb 17 12:50:57 2009 Nobuyoshi Nakada <nobu@r...> + + * string.c (rb_str_shared_replace): no need for + str_make_independent. + Tue Feb 17 05:41:08 2009 Koichi Sasada <ko1@a...> * compile.c: fix to add "ensure" codes across "while" clause Index: string.c =================================================================== --- string.c (revision 22367) +++ string.c (revision 22368) @@ -759,6 +759,8 @@ return rb_convert_type(str, T_STRING, "String", "to_str"); } +static inline void str_discard(VALUE str); + void rb_str_shared_replace(VALUE str, VALUE str2) { @@ -767,11 +769,8 @@ if (str == str2) return; enc = STR_ENC_GET(str2); cr = ENC_CODERANGE(str2); - rb_str_modify(str); + str_discard(str); OBJ_INFECT(str, str2); - if (!STR_SHARED_P(str) && !STR_EMBED_P(str)) { - xfree(RSTRING_PTR(str)); - } if (RSTRING_LEN(str2) <= RSTRING_EMBED_LEN_MAX) { STR_SET_EMBED(str); memcpy(RSTRING_PTR(str), RSTRING_PTR(str2), RSTRING_LEN(str2)+1); @@ -1194,6 +1193,17 @@ ENC_CODERANGE_CLEAR(str); } +static inline void +str_discard(VALUE str) +{ + str_modifiable(str); + if (!STR_SHARED_P(str) && !STR_EMBED_P(str)) { + xfree(RSTRING_PTR(str)); + RSTRING(str)->as.heap.ptr = 0; + RSTRING(str)->as.heap.len = 0; + } +} + void rb_str_associate(VALUE str, VALUE add) { @@ -3789,9 +3799,7 @@ if (STR_ASSOC_P(str2)) { str2 = rb_str_new4(str2); } - if (str_independent(str) && !STR_EMBED_P(str)) { - xfree(RSTRING_PTR(str)); - } + str_discard(str); if (STR_SHARED_P(str2)) { STR_SET_NOEMBED(str); RSTRING(str)->as.heap.len = len; @@ -3822,10 +3830,7 @@ static VALUE rb_str_clear(VALUE str) { - /* rb_str_modify() */ /* no need for str_make_independent */ - if (str_independent(str) && !STR_EMBED_P(str)) { - xfree(RSTRING_PTR(str)); - } + str_discard(str); STR_SET_EMBED(str); STR_SET_EMBED_LEN(str, 0); RSTRING_PTR(str)[0] = 0; Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 22367) +++ ruby_1_8/ChangeLog (revision 22368) @@ -1,3 +1,8 @@ +Tue Feb 17 12:50:57 2009 Nobuyoshi Nakada <nobu@r...> + + * string.c (rb_str_shared_replace): no need for + str_make_independent. + Mon Feb 16 16:47:43 2009 Nobuyoshi Nakada <nobu@r...> * win32/Makefile.sub (CRTDEFFLAGS): separated from DEFS. Index: ruby_1_8/version.h =================================================================== --- ruby_1_8/version.h (revision 22367) +++ ruby_1_8/version.h (revision 22368) @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.8.7" -#define RUBY_RELEASE_DATE "2009-02-16" +#define RUBY_RELEASE_DATE "2009-02-17" #define RUBY_VERSION_CODE 187 -#define RUBY_RELEASE_CODE 20090216 +#define RUBY_RELEASE_CODE 20090217 #define RUBY_PATCHLEVEL 5000 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 7 #define RUBY_RELEASE_YEAR 2009 #define RUBY_RELEASE_MONTH 2 -#define RUBY_RELEASE_DAY 16 +#define RUBY_RELEASE_DAY 17 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; Index: ruby_1_8/string.c =================================================================== --- ruby_1_8/string.c (revision 22367) +++ ruby_1_8/string.c (revision 22368) @@ -264,13 +264,14 @@ return rb_convert_type(str, T_STRING, "String", "to_str"); } +static inline void str_discard _((VALUE str)); + static void rb_str_shared_replace(str, str2) VALUE str, str2; { if (str == str2) return; - rb_str_modify(str); - if (!FL_TEST(str, ELTS_SHARED)) free(RSTRING(str)->ptr); + str_discard(str); if (NIL_P(str2)) { RSTRING(str)->ptr = 0; RSTRING(str)->len = 0; @@ -512,6 +513,16 @@ str_make_independent(str); } +static inline void +str_discard(VALUE str) +{ + if (str_independent(str)) { + xfree(RSTRING_PTR(str)); + RSTRING(str)->ptr = 0; + RSTRING(str)->len = 0; + } +} + void rb_str_associate(str, add) VALUE str, add; @@ -2212,9 +2223,7 @@ *bp = '\0'; rb_str_unlocktmp(dest); if (bang) { - if (str_independent(str)) { - free(RSTRING(str)->ptr); - } + str_discard(str); FL_UNSET(str, STR_NOCAPA); RSTRING(str)->ptr = buf; RSTRING(str)->aux.capa = blen; @@ -2312,9 +2321,7 @@ StringValue(str2); if (FL_TEST(str2, ELTS_SHARED)) { - if (str_independent(str)) { - free(RSTRING(str)->ptr); - } + str_discard(str); RSTRING(str)->len = RSTRING(str2)->len; RSTRING(str)->ptr = RSTRING(str2)->ptr; FL_SET(str, ELTS_SHARED); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/