estimateStringSearchCost estimates cost for O(n*m) string search operations such as indexOf and lastIndexOf.
(estimator checker.CostEstimator, target *checker.AstNode, args []checker.AstNode)
| 949 | // estimateStringSearchCost estimates cost for O(n*m) string search operations |
| 950 | // such as indexOf and lastIndexOf. |
| 951 | func estimateStringSearchCost(estimator checker.CostEstimator, target *checker.AstNode, args []checker.AstNode) *checker.CallEstimate { |
| 952 | if target == nil || len(args) < 1 { |
| 953 | return nil |
| 954 | } |
| 955 | targetSize := estimateSize(estimator, *target) |
| 956 | needleSize := estimateSize(estimator, args[0]) |
| 957 | searchSize := targetSize.Multiply(needleSize) |
| 958 | searchCost, _ := estimateStringScan(searchSize) |
| 959 | // Search cost is proportional to target size * substring size. |
| 960 | return callEstimate(searchCost.Add(callCostEstimate), nil) |
| 961 | } |
| 962 | |
| 963 | // estimateStringReplaceCost estimates cost for string replace operations. |
| 964 | // The cost accounts for search (O(n*m)) and potential output size growth. |
nothing calls this directly
no test coverage detected