aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-04-18 15:17:21 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-04-18 15:17:21 +0000
commit07cad43677ec51b1a84cc48b070c2975f71e0431 (patch)
treeba0f94de85510eb2d5a14660334815dd2e98e78b
parent398abd204d3b0826055d72c74ebdc62da3ce6641 (diff)
downloadruby-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
-rw-r--r--ChangeLog7
-rw-r--r--string.c12
2 files changed, 16 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 076d638be8..4ae42a09f6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sat Apr 19 00:17:20 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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.
+
Fri Apr 18 21:48:24 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_new_frozen): consider the shared string at
diff --git a/string.c b/string.c
index aa3eff8cd1..678118ef3d 100644
--- a/string.c
+++ b/string.c
@@ -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;