(e ast.Expr)
| 941 | } |
| 942 | |
| 943 | func (c *coster) computeSize(e ast.Expr) *SizeEstimate { |
| 944 | if size, ok := c.computedSizes[e.ID()]; ok { |
| 945 | return &size |
| 946 | } |
| 947 | if size := computeExprSize(e); size != nil { |
| 948 | return size |
| 949 | } |
| 950 | // Ensure size estimates are computed first as users may choose to override the costs that |
| 951 | // CEL would otherwise ascribe to the type. |
| 952 | node := astNode{expr: e, path: c.getPath(e), t: c.getType(e)} |
| 953 | if size := c.estimator.EstimateSize(node); size != nil { |
| 954 | // storing the computed size should reduce calls to EstimateSize() |
| 955 | c.computedSizes[e.ID()] = *size |
| 956 | return size |
| 957 | } |
| 958 | if size := computeTypeSize(c.getType(e)); size != nil { |
| 959 | return size |
| 960 | } |
| 961 | if e.Kind() == ast.IdentKind { |
| 962 | varName := e.AsIdent() |
| 963 | if v, ok := c.peekLocalVar(varName); ok && v.size != nil { |
| 964 | return v.size |
| 965 | } |
| 966 | } |
| 967 | return nil |
| 968 | } |
| 969 | |
| 970 | func (c *coster) setEntrySize(e ast.Expr, size *entrySizeEstimate) { |
| 971 | if size == nil { |
no test coverage detected