tr/nonutf8/nonutf8/c: simplify GROW calc
authorDavid Mitchell <davem@iabyn.com>
Fri, 19 Jan 2018 12:01:56 +0000 (12:01 +0000)
committerDavid Mitchell <davem@iabyn.com>
Fri, 19 Jan 2018 13:47:39 +0000 (13:47 +0000)
When, for each slot,  deciding whether to set OPpTRANS_GROWS, the
calculation is only done in one of 4 possible branches. It turns out that
in the other branches, the condition can never be true; but determining
that is subtle, and the assumption might break for future changes.  Move
the test outside the if/else tree so it can be seen to always apply.

So in theory this commit makes no function difference.

op.c

diff --git a/op.c b/op.c
index 4ea83d1..7f4618b 100644 (file)
--- a/op.c
+++ b/op.c
@@ -6660,10 +6660,13 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
                        tbl->map[i] = (short)i;
                }
                else {
-                   if (UVCHR_IS_INVARIANT(i) && ! UVCHR_IS_INVARIANT(r[j]))
-                       grows = 1;
                    tbl->map[i] = r[j++];
                }
+                if (   tbl->map[i] >= 0
+                    &&  UVCHR_IS_INVARIANT((UV)i)
+                    && !UVCHR_IS_INVARIANT((UV)(tbl->map[i]))
+                )
+                    grows = 1;
            }
        }