summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-03 07:25:21 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-03 07:25:21 +0000
commitbd5406dfa9c5f952556e39eb3f0fecb4d4ee99ff (patch)
tree4fe2bbd9508d49a38d80d32ebfea5bba074e52f5 /compile.c
parent55e606b36c7ab19d9326073ebd30b81d2325a007 (diff)
compile.c: fix string Range optimization with FSL
The optimization in [Feature #13355] needs to be detected differently to work with "frozen_string_literal: true" git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/compile.c b/compile.c
index 315e2dc92e..c7d6a41f99 100644
--- a/compile.c
+++ b/compile.c
@@ -2455,6 +2455,20 @@ same_debug_pos_p(LINK_ELEMENT *iobj1, LINK_ELEMENT *iobj2)
}
static int
+is_frozen_putstring(INSN *insn, VALUE *op)
+{
+ if (IS_INSN_ID(insn, putstring)) {
+ *op = OPERAND_AT(insn, 0);
+ return 1;
+ }
+ else if (IS_INSN_ID(insn, putobject)) { /* frozen_string_literal */
+ *op = OPERAND_AT(insn, 0);
+ return RB_TYPE_P(*op, T_STRING);
+ }
+ return 0;
+}
+
+static int
iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcallopt)
{
INSN *const iobj = (INSN *)list;
@@ -2574,16 +2588,15 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
* putobject "beg".."end"
*/
if (IS_INSN_ID(iobj, checkmatch)) {
- INSN *range = (INSN *)get_prev_insn(iobj);
- INSN *beg, *end;
+ INSN *range = (INSN *)get_prev_insn(iobj);
+ INSN *beg, *end;
+ VALUE str_beg, str_end;
if (range && IS_INSN_ID(range, newrange) &&
- (end = (INSN *)get_prev_insn(range)) != 0 &&
- IS_INSN_ID(end, putstring) &&
- (beg = (INSN *)get_prev_insn(end)) != 0 &&
- IS_INSN_ID(beg, putstring)) {
- VALUE str_beg = OPERAND_AT(beg, 0);
- VALUE str_end = OPERAND_AT(end, 0);
+ (end = (INSN *)get_prev_insn(range)) != 0 &&
+ is_frozen_putstring(end, &str_end) &&
+ (beg = (INSN *)get_prev_insn(end)) != 0 &&
+ is_frozen_putstring(beg, &str_beg)) {
int excl = FIX2INT(OPERAND_AT(range, 0));
VALUE lit_range = rb_range_new(str_beg, str_end, excl);