stringReplaceCostModel models replace: it searches the receiver for the needle and builds the result. Without a match the result is the receiver, and with one it contains the replacement, so it is at least the smaller of the two. Each of the at most n + 1 matches adds at most the replacement.
(id string)
| 995 | // it is at least the smaller of the two. Each of the at most n + 1 matches adds at most the |
| 996 | // replacement. |
| 997 | func stringReplaceCostModel(id string) cost.OverloadModel { |
| 998 | one := cost.Const(1) |
| 999 | maxSize := cost.Mul(cost.Sum(cost.Target(), one), cost.Sum(cost.Arg(1), one)) |
| 1000 | return cost.MemberOverload(id, |
| 1001 | cost.EvalCost(cost.Sum( |
| 1002 | cost.Const(cost.CallCost), |
| 1003 | cost.StringScan(cost.Mul( |
| 1004 | cost.AtLeastOneQuantity(cost.Length(cost.Target())), |
| 1005 | cost.AtLeastOneQuantity(cost.Length(cost.Arg(0))), |
| 1006 | )), |
| 1007 | cost.Length(cost.Result()), |
| 1008 | )), |
| 1009 | cost.ResultSize(cost.Ranged(cost.Min(cost.Target(), cost.Arg(1)), maxSize)), |
| 1010 | cost.BeforeVersion(1, cost.ResultSize(cost.Ranged( |
| 1011 | cost.Min(cost.Target(), cost.Sum(cost.Arg(1), one)), |
| 1012 | maxSize, |
| 1013 | ))), |
| 1014 | ) |
| 1015 | } |
| 1016 | |
| 1017 | // stringSplitCostModel models split: it scans the receiver and allocates the parts. |
| 1018 | func stringSplitCostModel(id string) cost.OverloadModel { |
no test coverage detected