summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-30 07:55:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-30 07:55:17 +0000
commitc39a8e326a67138238b25b9eeaff587a3ed13d4d (patch)
treefe1f4d62aa3fa8934bc496c9edffffacbb2ce89c /string.c
parent3d2ddca6b2d859c66fdd2498c564a86740969ded (diff)
* string.c (rb_str_substr): should share the shared string if
present, instead of the original string. (ruby-bugs:PR#528) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/string.c b/string.c
index d1cbd09..b551afe 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 {