[前][次][番号順一覧][スレッド一覧]

ruby-changes:33552

From: nobu <ko1@a...>
Date: Sat, 19 Apr 2014 00:17:25 +0900 (JST)
Subject: [ruby-changes:33552] nobu:r45633 (trunk): string.c: SHARABLE_SUBSTRING_P

nobu	2014-04-19 00:17:21 +0900 (Sat, 19 Apr 2014)

  New Revision: 45633

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45633

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/string.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45632)
+++ ChangeLog	(revision 45633)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Apr 19 00:17:20 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* string.c (rb_str_new_frozen): consider the shared string at
Index: string.c
===================================================================
--- string.c	(revision 45632)
+++ string.c	(revision 45633)
@@ -121,6 +121,12 @@ VALUE rb_cSymbol; https://github.com/ruby/ruby/blob/trunk/string.c#L121
 
 #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 https://github.com/ruby/ruby/blob/trunk/string.c#L1796
 {
     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 https://github.com/ruby/ruby/blob/trunk/string.c#L1906
     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, lon https://github.com/ruby/ruby/blob/trunk/string.c#L4419
     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;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]