MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / SizeHint

Function SizeHint

eval/compiler/flat_expr_builder.cc:269–290  ·  view source on GitHub ↗

Returns a hint for the number of program nodes (steps or subexpressions) that will be created for this expr.

Source from the content-addressed store, hash-verified

267// Returns a hint for the number of program nodes (steps or subexpressions) that
268// will be created for this expr.
269size_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

Callers 1

PreVisitExprMethod · 0.85

Calls 4

kind_caseMethod · 0.80
argsMethod · 0.80
has_targetMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected