Returns a hint for the number of program nodes (steps or subexpressions) that will be created for this expr.
| 267 | // Returns a hint for the number of program nodes (steps or subexpressions) that |
| 268 | // will be created for this expr. |
| 269 | size_t SizeHint(const cel::Expr& expr) { |
| 270 | switch (expr.kind_case()) { |
| 271 | case cel::ExprKindCase::kConstant: |
| 272 | return 1; |
| 273 | case cel::ExprKindCase::kIdentExpr: |
| 274 | return 1; |
| 275 | case cel::ExprKindCase::kSelectExpr: |
| 276 | return 2; |
| 277 | case cel::ExprKindCase::kCallExpr: |
| 278 | return expr.call_expr().args().size() + |
| 279 | (expr.call_expr().has_target() ? 2 : 1); |
| 280 | case cel::ExprKindCase::kListExpr: |
| 281 | return expr.list_expr().elements().size() + 1; |
| 282 | case cel::ExprKindCase::kStructExpr: |
| 283 | return expr.struct_expr().fields().size() + 1; |
| 284 | case cel::ExprKindCase::kMapExpr: |
| 285 | return 2 * expr.struct_expr().fields().size() + 1; |
| 286 | default: |
| 287 | return 1; |
| 288 | } |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | // Returns whether this comprehension appears to be a standard map/filter |
| 293 | // macro implementation. It is not exhaustive, so it is unsafe to use with |
no test coverage detected