diff options
| author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-12-30 07:55:17 +0000 |
|---|---|---|
| committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-12-30 07:55:17 +0000 |
| commit | 4719fbaac4df2400094a0f08103c4e87564e0340 (patch) | |
| tree | fe1f4d62aa3fa8934bc496c9edffffacbb2ce89c /string.c | |
| parent | b822f176a8cf97e5f4d84572c70a870f62a5a594 (diff) | |
| download | ruby-4719fbaac4df2400094a0f08103c4e87564e0340.tar.gz ruby-4719fbaac4df2400094a0f08103c4e87564e0340.tar.xz ruby-4719fbaac4df2400094a0f08103c4e87564e0340.zip | |
* 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
Diffstat (limited to 'string.c')
| -rw-r--r-- | string.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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 { |
