decOptimize optimizes the program plan by looking for common evaluation patterns and conditionally precomputing the result. - build list and map values with constant elements. - convert 'in' operations to set membership tests if possible.
()
| 111 | // - build list and map values with constant elements. |
| 112 | // - convert 'in' operations to set membership tests if possible. |
| 113 | func decOptimize() InterpretableDecoratorV2 { |
| 114 | return func(i InterpretableV2) (InterpretableV2, error) { |
| 115 | switch inst := i.(type) { |
| 116 | case *evalList: |
| 117 | return maybeBuildListLiteral(i, inst) |
| 118 | case *evalMap: |
| 119 | return maybeBuildMapLiteral(i, inst) |
| 120 | case InterpretableCall: |
| 121 | if inst.OverloadID() == overloads.InList { |
| 122 | return maybeOptimizeSetMembership(i, inst) |
| 123 | } |
| 124 | if overloads.IsTypeConversionFunction(inst.Function()) { |
| 125 | return maybeOptimizeConstUnary(i, inst) |
| 126 | } |
| 127 | } |
| 128 | return i, nil |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | // decRegexOptimizer compiles regex pattern string constants. |
| 133 | func decRegexOptimizer(regexOptimizations ...*RegexOptimization) InterpretableDecoratorV2 { |
no test coverage detected