ruby-changes:64153
From: Nobuyoshi <ko1@a...>
Date: Mon, 14 Dec 2020 19:29:53 +0900 (JST)
Subject: [ruby-changes:64153] 60f0c376f7 (master): Implemented shareable_constant_value op_asgn
https://git.ruby-lang.org/ruby.git/commit/?id=60f0c376f7 From 60f0c376f762aafadaba38e761d2dc9b0c1c0c82 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 9 Oct 2020 23:55:22 +0900 Subject: Implemented shareable_constant_value op_asgn diff --git a/parse.y b/parse.y index de3a8a8..986c67c 100644 --- a/parse.y +++ b/parse.y @@ -11876,7 +11876,20 @@ new_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, const YYLTYP https://github.com/ruby/ruby/blob/trunk/parse.y#L11876 if (lhs) { ID vid = lhs->nd_vid; YYLTYPE lhs_loc = lhs->nd_loc; + bool shareable = false; + switch (nd_type(lhs)) { + case NODE_CDECL: + case NODE_COLON2: + case NODE_COLON3: + shareable = true; + break; + default: + break; + } if (op == tOROP) { + if (shareable) { + rhs = shareable_constant_value(p, rhs, &rhs->nd_loc); + } lhs->nd_value = rhs; nd_set_loc(lhs, loc); asgn = NEW_OP_ASGN_OR(gettable(p, vid, &lhs_loc), lhs, loc); @@ -11890,13 +11903,20 @@ new_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, const YYLTYP https://github.com/ruby/ruby/blob/trunk/parse.y#L11903 } } else if (op == tANDOP) { + if (shareable) { + rhs = shareable_constant_value(p, rhs, &rhs->nd_loc); + } lhs->nd_value = rhs; nd_set_loc(lhs, loc); asgn = NEW_OP_ASGN_AND(gettable(p, vid, &lhs_loc), lhs, loc); } else { asgn = lhs; - asgn->nd_value = NEW_CALL(gettable(p, vid, &lhs_loc), op, NEW_LIST(rhs, &rhs->nd_loc), loc); + rhs = NEW_CALL(gettable(p, vid, &lhs_loc), op, NEW_LIST(rhs, &rhs->nd_loc), loc); + if (shareable) { + rhs = shareable_constant_value(p, rhs, &rhs->nd_loc); + } + asgn->nd_value = rhs; nd_set_loc(asgn, loc); } } @@ -11941,6 +11961,7 @@ new_const_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, const https://github.com/ruby/ruby/blob/trunk/parse.y#L11961 NODE *asgn; if (lhs) { + rhs = shareable_constant_value(p, rhs, loc); asgn = NEW_OP_CDECL(lhs, op, rhs, loc); } else { -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/