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

Method Optimize

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

Source from the content-addressed store, hash-verified

144}
145
146func (setsLib) Optimize(ctx *cel.OptimizerContext, a *ast.AST) *ast.AST {
147 root := ast.NavigateAST(a)
148 matches := ast.MatchDescendants(root, matchInConstantList(a))
149 for _, match := range matches {
150 call := match.AsCall()
151 listArg := call.Args()[1]
152 entries := make([]ast.EntryExpr, len(listArg.AsList().Elements()))
153 for i, elem := range listArg.AsList().Elements() {
154 var entry ast.EntryExpr
155 if r, found := a.ReferenceMap()[elem.ID()]; found && r.Value != nil {
156 entry = ctx.NewMapEntry(ctx.NewLiteral(r.Value), ctx.NewLiteral(types.True), false)
157 } else {
158 entry = ctx.NewMapEntry(elem, ctx.NewLiteral(types.True), false)
159 }
160 entries[i] = entry
161 }
162 mapArg := ctx.NewMap(entries)
163 ctx.UpdateExpr(listArg, mapArg)
164 }
165 return a
166}
167
168func matchInConstantList(a *ast.AST) ast.ExprMatcher {
169 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