ruby-changes:39274
From: nobu <ko1@a...>
Date: Thu, 23 Jul 2015 14:17:01 +0900 (JST)
Subject: [ruby-changes:39274] nobu:r51355 (trunk): string.c: new string for fake string
nobu 2015-07-23 14:14:53 +0900 (Thu, 23 Jul 2015) New Revision: 51355 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51355 Log: string.c: new string for fake string * string.c (fstr_update_callback): create new string for fake string, and pool shared target unless substring. Modified files: trunk/string.c Index: string.c =================================================================== --- string.c (revision 51354) +++ string.c (revision 51355) @@ -155,6 +155,9 @@ VALUE rb_cSymbol; https://github.com/ruby/ruby/blob/trunk/string.c#L155 #define SHARABLE_SUBSTRING_P(beg, len, end) 1 #endif +static VALUE str_new_static(VALUE klass, const char *ptr, long len, int encindex); +static void str_make_independent_expand(VALUE str, long expand); + static rb_encoding * get_actual_encoding(const int encidx, VALUE str) { @@ -244,12 +247,18 @@ fstr_update_callback(st_data_t *key, st_ https://github.com/ruby/ruby/blob/trunk/string.c#L247 return ST_STOP; } else { - if (STR_SHARED_P(str)) { /* str should not be shared */ - str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), STR_ENC_GET(str)); - OBJ_FREEZE(str); + if (FL_TEST_RAW(str, STR_FAKESTR)) { + str = str_new_static(rb_cString, RSTRING(str)->as.heap.ptr, + RSTRING(str)->as.heap.len, + ENCODING_GET(str)); + OBJ_FREEZE_RAW(str); } else { str = rb_str_new_frozen(str); + if (STR_SHARED_P(str)) { /* str should not be shared */ + /* shared substring */ + str_make_independent_expand(str, 0L); + } } RBASIC(str)->flags |= RSTRING_FSTR; @@ -280,6 +289,8 @@ register_fstring(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L289 fstr_update_callback, (st_data_t)&ret); } while (ret == Qundef); + assert(OBJ_FROZEN(ret)); + assert(!FL_TEST_RAW(ret, STR_FAKESTR)); return ret; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/