From 86db656415a2e05b573d95d813d6ca5a26b55d07 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 17 Dec 2002 10:34:30 +0000 Subject: [PATCH] * 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 --- ChangeLog | 11 +++++++++++ eval.c | 18 ++++++++++++++++++ node.h | 2 ++ parse.y | 3 ++- string.c | 14 ++++++++++++-- 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c276212c4..8166a7dda6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Tue Dec 17 19:29:45 2002 Nobuyoshi Nakada + + * 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] + Tue Dec 17 04:03:45 2002 Tanaka Akira * lib/open-uri.rb: new file. diff --git a/eval.c b/eval.c index bfa7330999..e6ae4c41a7 100644 --- a/eval.c +++ b/eval.c @@ -1881,6 +1881,7 @@ is_defined(self, node, buf) goto check_bound; case NODE_CALL: + case NODE_ATTRASGN: PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { val = rb_eval(self, node->nd_recv); @@ -2742,6 +2743,23 @@ rb_eval(self, n) rb_eval(self, node->nd_body)); break; + case NODE_ATTRASGN: + { + VALUE recv; + int argc; VALUE *argv; /* used in SETUP_ARGS */ + TMP_PROTECT; + + BEGIN_CALLARGS; + recv = rb_eval(self, node->nd_recv); + SETUP_ARGS(node->nd_args); + END_CALLARGS; + + SET_CURRENT_SOURCE(); + rb_call(CLASS_OF(recv),recv,node->nd_mid,argc,argv,0); + result = argv[argc-1]; + } + break; + case NODE_CALL: { VALUE recv; diff --git a/node.h b/node.h index 691a4cd8c1..069045d593 100644 --- a/node.h +++ b/node.h @@ -123,6 +123,7 @@ enum node_type { NODE_MEMO, NODE_IFUNC, NODE_DSYM, + NODE_ATTRASGN, NODE_LAST }; @@ -332,6 +333,7 @@ typedef struct RNode { #define NEW_POSTEXE() rb_node_newnode(NODE_POSTEXE,0,0,0) #define NEW_DMETHOD(b) rb_node_newnode(NODE_DMETHOD,0,0,b) #define NEW_BMETHOD(b) rb_node_newnode(NODE_BMETHOD,0,0,b) +#define NEW_ATTRASGN(r,m,a) rb_node_newnode(NODE_ATTRASGN,r,m,a) #define NOEX_PUBLIC 0 #define NOEX_NOSUPER 1 diff --git a/parse.y b/parse.y index 1e5696b97c..74d4d09039 100644 --- a/parse.y +++ b/parse.y @@ -4705,7 +4705,7 @@ attrset(recv, id) ID id; { value_expr(recv); - return NEW_CALL(recv, rb_id_attrset(id), 0); + return NEW_ATTRASGN(recv, rb_id_attrset(id), 0); } static void @@ -4765,6 +4765,7 @@ node_assign(lhs, rhs) lhs->nd_value = rhs; break; + case NODE_ATTRASGN: case NODE_CALL: lhs->nd_args = arg_add(lhs->nd_args, rhs); break; diff --git a/string.c b/string.c index 754db30059..5ca6aae4d1 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; }