MCPcopy
hub / github.com/expr-lang/expr / Optimize

Function Optimize

optimizer/optimizer.go:11–49  ·  view source on GitHub ↗
(node *Node, config *conf.Config)

Source from the content-addressed store, hash-verified

9)
10
11func Optimize(node *Node, config *conf.Config) error {
12 Walk(node, &inArray{})
13 for limit := 1000; limit >= 0; limit-- {
14 fold := &fold{}
15 Walk(node, fold)
16 if fold.err != nil {
17 return fold.err
18 }
19 if !fold.applied {
20 break
21 }
22 }
23 if config != nil && len(config.ConstFns) > 0 {
24 for limit := 100; limit >= 0; limit-- {
25 constExpr := &constExpr{
26 fns: config.ConstFns,
27 }
28 Walk(node, constExpr)
29 if constExpr.err != nil {
30 return constExpr.err
31 }
32 if !constExpr.applied {
33 break
34 }
35 }
36 }
37 Walk(node, &inRange{})
38 Walk(node, &filterMap{})
39 Walk(node, &filterLen{})
40 Walk(node, &filterLast{})
41 Walk(node, &filterFirst{})
42 Walk(node, &predicateCombination{})
43 Walk(node, &sumRange{})
44 Walk(node, &sumArray{})
45 Walk(node, &sumMap{})
46 Walk(node, &countAny{})
47 Walk(node, &countThreshold{})
48 return nil
49}
50
51var (
52 boolType = reflect.TypeOf(true)

Calls 1

WalkFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…