OP_SORT: store start of block in null->op_next
authorDavid Mitchell <davem@iabyn.com>
Wed, 5 Mar 2014 14:44:41 +0000 (14:44 +0000)
committerDavid Mitchell <davem@iabyn.com>
Sun, 16 Mar 2014 18:34:37 +0000 (18:34 +0000)
commit932bca295d64243e2ef2aeaacc779b68cc05e1b2
tree8c5e02e3d9bd77cc733812159167425df1186b4f
parent22240f589eab50022218e3541b91a487c29a729b
OP_SORT: store start of block in null->op_next

When a sort with a code block, like sort { BLOCK } arg, ...
is compiled, it comes out like

     sort
        pushmark
        null
           scope
              BLOCK
        arg
        ...

(The 'scope' may be instead be 'ex-leave' depending on circumstances).

At run time, pp_sort() navigates its way down from the sort op to find the
start op of the BLOCK. We can shorten this process slightly by storing the
start of BLOCK in the otherwise unused op_next field of the OP_NULL.
Effectively we are using the null->op_next field as a surrogate op_other
field for the op_sort (which doesn't have a spare field we could store
the pointer in).

The main point of this commit however is not the slight speed up from
skipping a couple of pointer follows at run-time; rather that it will
shortly allow us to trim any null ops from the beginning of the BLOCK. We
can't do this directly, as that would involve changing the scope->op_first
pointer, which might confuse B:: type modules.
op.c
pp_sort.c