summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-17 10:34:30 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-17 10:34:30 +0000
commit86db656415a2e05b573d95d813d6ca5a26b55d07 (patch)
tree379c349bd378072c2907f4e6579b677573a2e087 /string.c
parent3a20ed532b57da1e58287a5c53abe14400a085f4 (diff)
* node.h (NODE_ATTRASGN): new node, assignment to attribute.
[ruby-core:00637]. * eval.c (is_defined, rb_eval): ditto. * parse.y (attrset, node_assign): ditto. * string.c (rb_str_substr): tail sharing. [ruby-core:00650] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/string.c b/string.c
index 754db30..5ca6aae 100644
--- a/string.c
+++ b/string.c
@@ -474,8 +474,18 @@ rb_str_substr(str, beg, len)
}
if (len == 0) return rb_str_new5(str,0,0);
- str2 = rb_str_new5(str,RSTRING(str)->ptr+beg, len);
- OBJ_INFECT(str2, str);
+ if (len > sizeof(struct RString)/2 &&
+ beg + len == RSTRING(str)->len &&
+ !FL_TEST(str, STR_ASSOC)) {
+ if (!FL_TEST(str, ELTS_SHARED)) str = rb_str_new4(str);
+ str2 = rb_str_new3(str);
+ RSTRING(str2)->ptr += beg;
+ RSTRING(str2)->len = len;
+ }
+ else {
+ str2 = rb_str_new5(str, RSTRING(str)->ptr+beg, len);
+ OBJ_INFECT(str2, str);
+ }
return str2;
}