From 4719fbaac4df2400094a0f08103c4e87564e0340 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 30 Dec 2002 07:55:17 +0000 Subject: * string.c (rb_str_substr): should share the shared string if present, instead of the original string. (ruby-bugs:PR#528) git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index d1cbd09cc..b551afe72 100644 --- a/string.c +++ b/string.c @@ -500,9 +500,12 @@ rb_str_substr(str, beg, len) if (len > sizeof(struct RString)/2 && beg + len == RSTRING(str)->len && !FL_TEST(str, STR_ASSOC)) { - if (!FL_TEST(str, ELTS_SHARED)) str = str_new4(CLASS_OF(str), str); + if (FL_TEST(str, ELTS_SHARED)) + str = RSTRING(str)->aux.shared; + else + str = str_new4(CLASS_OF(str), str); str2 = rb_str_new3(str); - RSTRING(str2)->ptr += beg; + RSTRING(str2)->ptr += RSTRING(str2)->len - len; RSTRING(str2)->len = len; } else { -- cgit