summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-23 05:14:53 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-23 05:14:53 (GMT)
commitf965866f4f0a00c8179a1097e89fb4e61f71a92a (patch)
treeb1c6588c65bb70ec1c26db7fc61fc15cf9bc29fd /string.c
parent8ea11e8e1e8e13328efcd55941e5d5108511ef76 (diff)
string.c: new string for fake string
* string.c (fstr_update_callback): create new string for fake string, and pool shared target unless substring. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/string.c b/string.c
index 5d07da1..46dafed 100644
--- a/string.c
+++ b/string.c
@@ -155,6 +155,9 @@ VALUE rb_cSymbol;
#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_data_t *value, st_data_t arg, int existi
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)
fstr_update_callback, (st_data_t)&ret);
} while (ret == Qundef);
+ assert(OBJ_FROZEN(ret));
+ assert(!FL_TEST_RAW(ret, STR_FAKESTR));
return ret;
}