estimateSubstringCost estimates the cost for an O(n) traversal and allocation.
(estimator checker.CostEstimator, target *checker.AstNode, args []checker.AstNode)
| 931 | |
| 932 | // estimateSubstringCost estimates the cost for an O(n) traversal and allocation. |
| 933 | func estimateSubstringCost(estimator checker.CostEstimator, target *checker.AstNode, args []checker.AstNode) *checker.CallEstimate { |
| 934 | if target == nil || len(args) < 1 || len(args) > 2 { |
| 935 | return nil |
| 936 | } |
| 937 | targetSize := estimateSize(estimator, *target) |
| 938 | cost, _ := estimateStringScan(targetSize) |
| 939 | |
| 940 | start := nodeAsUintValue(args[0], 0) |
| 941 | end := targetSize.Max |
| 942 | if len(args) == 2 { |
| 943 | end = nodeAsUintValue(args[1], end) |
| 944 | } |
| 945 | resultSize := fixedSizeEstimate(end - start) |
| 946 | return callEstimate(cost.Add(callCostEstimate).Add(resultSize.AsCost()), &resultSize) |
| 947 | } |
| 948 | |
| 949 | // estimateStringSearchCost estimates cost for O(n*m) string search operations |
| 950 | // such as indexOf and lastIndexOf. |
nothing calls this directly
no test coverage detected