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