()
| 357 | } |
| 358 | |
| 359 | func estimateExtractAllCost() checker.FunctionEstimator { |
| 360 | return func(c checker.CostEstimator, target *checker.AstNode, args []checker.AstNode) *checker.CallEstimate { |
| 361 | if len(args) == 2 { |
| 362 | targetSize := estimateSize(c, args[0]) |
| 363 | // Fixed size estimate of +1 is added for safety from zero size args. |
| 364 | // The target cost is the size of the target string, scaled by a traversal factor. |
| 365 | targetCost := targetSize.Add(fixedSizeEstimate(1)).MultiplyByCostFactor(common.StringTraversalCostFactor) |
| 366 | // The regex cost is the size of the regex pattern, scaled by a complexity factor. |
| 367 | regexCost := estimateSize(c, args[1]).Add(fixedSizeEstimate(1)).MultiplyByCostFactor(common.RegexStringLengthCostFactor) |
| 368 | // The result is a list of strings. Worst Case: it's contents are the size of the entire target. |
| 369 | resultSize := rangedSizeEstimate(0, targetSize.Max) |
| 370 | // The cost to allocate the result list is its base cost plus the size of its contents. |
| 371 | allocationSize := resultSize.Add(fixedSizeEstimate(common.ListCreateBaseCost)) |
| 372 | // The total cost is the search cost (target + regex) plus the allocation cost for the result list. |
| 373 | return callEstimate( |
| 374 | targetCost.Multiply(regexCost).Add(checker.CostEstimate(allocationSize)), |
| 375 | &resultSize, |
| 376 | ) |
| 377 | } |
| 378 | return nil |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | func estimateReplaceCost() checker.FunctionEstimator { |
| 383 | return func(c checker.CostEstimator, target *checker.AstNode, args []checker.AstNode) *checker.CallEstimate { |
no test coverage detected