Package com.saxonica.ee.optim

## Class CommonSubexpressionPromoter

- java.lang.Object
- - com.saxonica.ee.optim.CommonSubexpressionPromoter

-     public class CommonSubexpressionPromoter
      extends java.lang.Object

  This class is responsible for identifying and extracting common subexpressions within an expression. For example the expression (x/y/z = 3 or x/y/z = 4) is turned into (let $zz = x/y/z return ($zz = 3 or $zz = 4). For simplicity, in this initial version: (a) we extract at most one subexpression: the one that has the highest value of instances*cost. (b) we restrict the scope of the search for duplicates to that part of the expression tree that shares the same dynamic context (local variables, focus, etc).

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `CommonSubexpressionPromoter​(OptimizerEE opt)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Expression` | `promoteCommonSubexpressions​(Expression in)` | Search for duplicate subexpressions within an expression tree, and if one is found, generate a local variable bound to the common subexpression, replacing the original subexpression with a reference to the new local variable

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CommonSubexpressionPromoter

          public CommonSubexpressionPromoter​(OptimizerEE opt)

  - ### Method Detail

    - #### promoteCommonSubexpressions

          public Expression promoteCommonSubexpressions​(Expression in)

      Search for duplicate subexpressions within an expression tree, and if one is found, generate a local variable bound to the common subexpression, replacing the original subexpression with a reference to the new local variable
      Parameters:
        `in` - the expression to be searched
      Returns:
        the new expression, with common subexpressions promoted; or the original expression unchanged.