From ddcffd84df3b0cf7b2325bed1db38b89bf19fa53 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Mon, 8 Jan 2018 16:14:17 +0000 Subject: [PATCH] S_pmtrans(): add assert and simplify conditional in tr/search/replace/c, the number of 'paired' replacement chars will always be <= length(replace). Assert this, and thus simplify a couple of conditionals from >= to ==. It should make no difference to execution, but reduces the cognitive load. --- op.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/op.c b/op.c index 6504ef0..5652858 100644 --- a/op.c +++ b/op.c @@ -6644,7 +6644,7 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl) tbl[t[i]] = -1; for (i = 0, j = 0; i < 256; i++) { if (!tbl[i]) { - if (j >= (I32)rlen) { + if (j == (I32)rlen) { if (del) tbl[i] = -2; else if (rlen) @@ -6659,6 +6659,8 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl) } } } + + assert(j <= (I32)rlen); if (!del) { if (!rlen) { /* empty replacement list */ @@ -6666,7 +6668,7 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl) if (!squash) o->op_private |= OPpTRANS_IDENTICAL; } - else if (j >= (I32)rlen) + else if (j == (I32)rlen) /* no more replacement chars than search chars */ j = rlen - 1; else { -- 1.8.3.1