()
| 336 | } |
| 337 | |
| 338 | func estimateExtractCost() checker.FunctionEstimator { |
| 339 | return func(c checker.CostEstimator, target *checker.AstNode, args []checker.AstNode) *checker.CallEstimate { |
| 340 | if len(args) == 2 { |
| 341 | targetSize := estimateSize(c, args[0]) |
| 342 | // Fixed size estimate of +1 is added for safety from zero size args. |
| 343 | // The target cost is the size of the target string, scaled by a traversal factor. |
| 344 | targetCost := targetSize.Add(fixedSizeEstimate(1)).MultiplyByCostFactor(common.StringTraversalCostFactor) |
| 345 | // The regex cost is the size of the regex pattern, scaled by a complexity factor. |
| 346 | regexCost := estimateSize(c, args[1]).Add(fixedSizeEstimate(1)).MultiplyByCostFactor(common.RegexStringLengthCostFactor) |
| 347 | // The result is a single string. Worst Case: it's the size of the entire target. |
| 348 | resultSize := rangedSizeEstimate(0, targetSize.Max) |
| 349 | // The total cost is the search cost (target + regex) plus the allocation cost for the result string. |
| 350 | return callEstimate( |
| 351 | regexCost.Multiply(targetCost).Add(checker.CostEstimate(resultSize)), |
| 352 | &resultSize, |
| 353 | ) |
| 354 | } |
| 355 | return nil |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | func estimateExtractAllCost() checker.FunctionEstimator { |
| 360 | return func(c checker.CostEstimator, target *checker.AstNode, args []checker.AstNode) *checker.CallEstimate { |
no test coverage detected