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

Function isOptimizableMapInsert

interpreter/planner.go:780–807  ·  view source on GitHub ↗

isOptimizableMapInsert mirrors cel-cpp's IsOptimizableMapInsert. Returns whether this comprehension appears to be a macro implementation for map transformations.

(fold ast.ComprehensionExpr)

Source from the content-addressed store, hash-verified

778// Returns whether this comprehension appears to be a macro implementation for map
779// transformations.
780func isOptimizableMapInsert(fold ast.ComprehensionExpr) bool {
781 if fold.IterVar() == "" || fold.IterVar2() == "" {
782 return false
783 }
784 accuVar := fold.AccuVar()
785 if accuVar == "" || !isIdentNamed(fold.Result(), accuVar) {
786 return false
787 }
788 if fold.AccuInit().Kind() != ast.MapKind || fold.AccuInit().AsMap().Size() != 0 {
789 return false
790 }
791 step := fold.LoopStep()
792 if step.Kind() != ast.CallKind {
793 return false
794 }
795 call := step.AsCall()
796 if call.FunctionName() == operators.Conditional && len(call.Args()) == 3 {
797 branch := call.Args()[1]
798 if branch.Kind() != ast.CallKind {
799 return false
800 }
801 call = branch.AsCall()
802 }
803 args := call.Args()
804 return call.FunctionName() == mapInsertFunction &&
805 (len(args) == 2 || len(args) == 3) &&
806 isIdentNamed(args[0], accuVar)
807}
808
809// isIdentNamed reports whether the expression is an identifier with the given name.
810func isIdentNamed(e ast.Expr, name string) bool {

Callers 1

isMutableAccuSafeFunction · 0.85

Calls 13

isIdentNamedFunction · 0.85
IterVarMethod · 0.65
IterVar2Method · 0.65
AccuVarMethod · 0.65
ResultMethod · 0.65
KindMethod · 0.65
AccuInitMethod · 0.65
SizeMethod · 0.65
AsMapMethod · 0.65
LoopStepMethod · 0.65
AsCallMethod · 0.65
FunctionNameMethod · 0.65

Tested by

no test coverage detected