estimateStringJoinCost estimates cost for string join operations. Join iterates over all list elements and concatenates them, so cost is proportional to the total size of all elements plus separator overhead.
(estimator checker.CostEstimator, target *checker.AstNode, args []checker.AstNode)
| 1005 | // Join iterates over all list elements and concatenates them, so cost is |
| 1006 | // proportional to the total size of all elements plus separator overhead. |
| 1007 | func estimateStringJoinCost(estimator checker.CostEstimator, target *checker.AstNode, args []checker.AstNode) *checker.CallEstimate { |
| 1008 | if target == nil { |
| 1009 | return nil |
| 1010 | } |
| 1011 | targetSize := estimateSize(estimator, *target) |
| 1012 | sepSize := fixedSizeEstimate(0) |
| 1013 | if len(args) >= 1 { |
| 1014 | sepSize = estimateSize(estimator, args[0]) |
| 1015 | } |
| 1016 | // Traversal cost proportional to the number of list elements. |
| 1017 | traversalCost := targetSize.Add(fixedSizeEstimate(1)).MultiplyByCostFactor(stringCostFactor) |
| 1018 | // Result size: sum of element sizes + (n-1) * separator size. |
| 1019 | // Worst case estimate: use list size * max element size + list size * separator size. |
| 1020 | maxResultSize := safeAdd(safeMul(targetSize.Max, (safeAdd(1, sepSize.Max))), sepSize.Max) |
| 1021 | resultSize := rangedSizeEstimate(0, maxResultSize) |
| 1022 | cost := traversalCost.Add(resultSize.MultiplyByCostFactor(1)).Add(callCostEstimate) |
| 1023 | return callEstimate(cost, &resultSize) |
| 1024 | } |
| 1025 | |
| 1026 | // Runtime cost tracking functions for string extensions. |
| 1027 | // |
nothing calls this directly
no test coverage detected