MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Optimize

Method Optimize

ext/sets.go:138–158  ·  view source on GitHub ↗
(ctx *cel.OptimizerContext, a *ast.AST)

Source from the content-addressed store, hash-verified

136}
137
138func (setsLib) Optimize(ctx *cel.OptimizerContext, a *ast.AST) *ast.AST {
139 root := ast.NavigateAST(a)
140 matches := ast.MatchDescendants(root, matchInConstantList(a))
141 for _, match := range matches {
142 call := match.AsCall()
143 listArg := call.Args()[1]
144 entries := make([]ast.EntryExpr, len(listArg.AsList().Elements()))
145 for i, elem := range listArg.AsList().Elements() {
146 var entry ast.EntryExpr
147 if r, found := a.ReferenceMap()[elem.ID()]; found && r.Value != nil {
148 entry = ctx.NewMapEntry(ctx.NewLiteral(r.Value), ctx.NewLiteral(types.True), false)
149 } else {
150 entry = ctx.NewMapEntry(elem, ctx.NewLiteral(types.True), false)
151 }
152 entries[i] = entry
153 }
154 mapArg := ctx.NewMap(entries)
155 ctx.UpdateExpr(listArg, mapArg)
156 }
157 return a
158}
159
160func matchInConstantList(a *ast.AST) ast.ExprMatcher {
161 return func(e ast.NavigableExpr) bool {

Callers

nothing calls this directly

Calls 13

NavigateASTFunction · 0.92
MatchDescendantsFunction · 0.92
matchInConstantListFunction · 0.85
ReferenceMapMethod · 0.80
UpdateExprMethod · 0.80
AsCallMethod · 0.65
ArgsMethod · 0.65
ElementsMethod · 0.65
AsListMethod · 0.65
IDMethod · 0.65
NewMapEntryMethod · 0.65
NewLiteralMethod · 0.65

Tested by

no test coverage detected