expand-sequence: Invoke is-expandable only once per expansion head

`is-expandable` is an expensive XPath, and it was being invoked twice per
node: one for each complementary `match`.

DEV-10806
main
Mike Gerwitz 2023-10-05 10:23:08 -04:00
parent 3d56fe289d
commit 5e883e3c4f
1 changed files with 16 additions and 17 deletions

View File

@ -172,17 +172,30 @@
--> -->
<!-- <!--
We must continue to expand expandable nodes; otherwise, nested
expansions would never take place.
When we encounter a head that is not expandable, it will be When we encounter a head that is not expandable, it will be
immediately hoisted, as there is no work to be done. immediately hoisted, as there is no work to be done.
The result of this operation will be a sequence of nodes, one of The result of this operation will be a sequence of nodes, one of
them being the hoisted node, and the last being the remaining them being the hoisted node, and the last being the remaining
expansion sequence. @xref{Node Hoisting}. expansion sequence. @xref{Node Hoisting}.
Once expansion is complete, by the definition of
@ttref{eseq:is-expandable#1}, expansion will halt.
--> -->
<template mode="_eseq:expand" as="node()+" <template mode="_eseq:expand" as="node()+"
match="*[ node()[1][ match="*[ node() ]">
not( eseq:is-expandable( . ) ) ] ]"> <choose>
<sequence select="_eseq:hoist( . )" /> <when test="node()[1][ eseq:is-expandable( . ) ]">
<sequence select="_eseq:expand-head( . )" />
</when>
<otherwise>
<sequence select="_eseq:hoist( . )" />
</otherwise>
</choose>
</template> </template>
@ -196,20 +209,6 @@
so we need only continue to expand nodes as necessary. so we need only continue to expand nodes as necessary.
--> -->
<!--
We must continue to expand expandable nodes; otherwise, nested
expansions would never take place.
Once expansion is complete, by the definition of
@ttref{eseq:is-expandable#1}, expansion will halt.
-->
<template mode="_eseq:expand" as="element()"
match="*[ node()[1][
eseq:is-expandable( . ) ] ]">
<sequence select="_eseq:expand-head( . )" />
</template>
<!-- <!--
Up until this point, we have been assuming that there is an actual Up until this point, we have been assuming that there is an actual
head node to process; this may not be the case. In fact, we are head node to process; this may not be the case. In fact, we are