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

Function scanOptTargets

cel/program.go:287–304  ·  view source on GitHub ↗

scanOptTargets walks the AST once and reports whether the Optimize() decorator (needOpt) and the regex-constant compiler (needRegex) have any target node present. The conditions are a superset of what each decorator acts on, so a false negative — skipping a decorator that would have optimized someth

(root ast.Expr)

Source from the content-addressed store, hash-verified

285// acts on, so a false negative — skipping a decorator that would have
286// optimized something — is impossible.
287func scanOptTargets(root ast.Expr) (needOpt, needRegex bool) {
288 ast.PostOrderVisit(root, ast.NewExprVisitor(func(e ast.Expr) {
289 switch e.Kind() {
290 case ast.ListKind, ast.MapKind:
291 needOpt = true // maybeBuildListLiteral / maybeBuildMapLiteral
292 case ast.CallKind:
293 switch fn := e.AsCall().FunctionName(); {
294 case fn == overloads.Matches:
295 needRegex = true
296 case fn == operators.In || fn == operators.OldIn:
297 needOpt = true // maybeOptimizeSetMembership
298 case overloads.IsTypeConversionFunction(fn):
299 needOpt = true // maybeOptimizeConstUnary
300 }
301 }
302 }))
303 return
304}
305
306// newProgram creates a program instance with an environment, an ast, and an optional list of
307// ProgramOption values.

Callers 1

newProgramFunction · 0.85

Calls 6

PostOrderVisitFunction · 0.92
NewExprVisitorFunction · 0.92
IsTypeConversionFunctionFunction · 0.92
KindMethod · 0.65
FunctionNameMethod · 0.65
AsCallMethod · 0.65

Tested by

no test coverage detected