diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-04-18 15:17:21 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-04-18 15:17:21 +0000 |
commit | 07cad43677ec51b1a84cc48b070c2975f71e0431 (patch) | |
tree | ba0f94de85510eb2d5a14660334815dd2e98e78b /string.c | |
parent | 398abd204d3b0826055d72c74ebdc62da3ce6641 (diff) | |
download | ruby-07cad43677ec51b1a84cc48b070c2975f71e0431.tar.gz |
string.c: SHARABLE_SUBSTRING_P
* string.c (SHARABLE_SUBSTRING_P): predicate if substring can be
shared with the original string. true if just at the end of the
original string, for the time being. all substring will be able to
be shared in the future.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -121,6 +121,12 @@ VALUE rb_cSymbol; #define STR_ENC_GET(str) get_encoding(str) +#if 1 +#define SHARABLE_SUBSTRING_P(beg, len, end) ((beg) + (len) == (end)) +#else +#define SHARABLE_SUBSTRING_P(beg, len, end) 1 +#endif + rb_encoding *rb_enc_get_from_index(int index); static rb_encoding * @@ -1790,7 +1796,7 @@ rb_str_subseq(VALUE str, long beg, long len) { VALUE str2; - if (RSTRING_EMBED_LEN_MAX < len) { + if (RSTRING_EMBED_LEN_MAX < len && SHARABLE_SUBSTRING_P(beg, len, RSTRING_LEN(str))) { long olen; str2 = rb_str_new_shared(rb_str_new_frozen(str)); RSTRING(str2)->as.heap.ptr += beg; @@ -1900,7 +1906,7 @@ rb_str_substr(VALUE str, long beg, long len) char *p = rb_str_subpos(str, beg, &len); if (!p) return Qnil; - if (len > RSTRING_EMBED_LEN_MAX) { + if (len > RSTRING_EMBED_LEN_MAX && SHARABLE_SUBSTRING_P(p, len, RSTRING_END(str))) { long ofs = p - RSTRING_PTR(str); str2 = rb_str_new_frozen(str); str2 = str_new_shared(rb_obj_class(str2), str2); @@ -4413,7 +4419,7 @@ str_byte_substr(VALUE str, long beg, long len) else p = s + beg; - if (len > RSTRING_EMBED_LEN_MAX) { + if (len > RSTRING_EMBED_LEN_MAX && SHARABLE_SUBSTRING_P(beg, len, n)) { str2 = rb_str_new_frozen(str); str2 = str_new_shared(rb_obj_class(str2), str2); RSTRING(str2)->as.heap.ptr += beg; |