Cost estimates the cost of the parsed and type checked CEL expression.
(checked *ast.AST, estimator CostEstimator, opts ...CostOption)
| 283 | |
| 284 | // Cost estimates the cost of the parsed and type checked CEL expression. |
| 285 | func Cost(checked *ast.AST, estimator CostEstimator, opts ...CostOption) (CostEstimate, error) { |
| 286 | c := &coster{ |
| 287 | checkedAST: checked, |
| 288 | estimator: estimator, |
| 289 | overloadEstimators: map[string]FunctionEstimator{}, |
| 290 | exprPaths: map[int64][]string{}, |
| 291 | localVars: make(scopes), |
| 292 | computedSizes: map[int64]SizeEstimate{}, |
| 293 | computedEntrySizes: map[int64]entrySizeEstimate{}, |
| 294 | presenceTestCost: FixedCostEstimate(1), |
| 295 | } |
| 296 | for _, opt := range opts { |
| 297 | err := opt(c) |
| 298 | if err != nil { |
| 299 | return CostEstimate{}, err |
| 300 | } |
| 301 | } |
| 302 | return c.cost(checked.Expr()), nil |
| 303 | } |
| 304 | |
| 305 | type coster struct { |
| 306 | // exprPaths maps from Expr Id to field path. |