Cost estimation functions for string extensions. These functions provide compile-time cost estimates proportional to the size of the input string(s), ensuring that the CEL cost system accurately reflects the computational work performed by string operations. estimateSubstringCost estimates the cost
(estimator cost.Estimator, target *cost.AstNode, args []cost.AstNode)
| 874 | |
| 875 | // estimateSubstringCost estimates the cost for an O(n) traversal and allocation. |
| 876 | func estimateSubstringCost(estimator cost.Estimator, target *cost.AstNode, args []cost.AstNode) *cost.CallEstimate { |
| 877 | if target == nil || len(args) < 1 || len(args) > 2 { |
| 878 | return nil |
| 879 | } |
| 880 | targetSize := cost.EstimateSize(estimator, *target) |
| 881 | evalCost, _ := cost.EstimateStringScan(targetSize) |
| 882 | |
| 883 | start := cost.NodeAsUintValue(args[0], 0) |
| 884 | end := targetSize.Max |
| 885 | if len(args) == 2 { |
| 886 | end = cost.NodeAsUintValue(args[1], end) |
| 887 | } |
| 888 | resultSize := cost.FixedSizeEstimate(end - start) |
| 889 | return cost.NewCallEstimate(evalCost.Add(cost.CallCostEstimate).Add(resultSize.AsCost()), &resultSize) |
| 890 | } |
| 891 | |
| 892 | // splitSize bounds the size of the parts of a string of size n: at most n + 1 parts of at most n |
| 893 | // each. Under the aggregate strategy the parts hold at most the string's content plus one unit |
nothing calls this directly
no test coverage detected