MCPcopy Create free account
hub / github.com/cel-expr/cel-go / stringReplaceCostModel

Function stringReplaceCostModel

ext/strings.go:997–1015  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

995// it is at least the smaller of the two. Each of the at most n + 1 matches adds at most the
996// replacement.
997func 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.
1018func stringSplitCostModel(id string) cost.OverloadModel {

Callers 1

CompileOptionsMethod · 0.85

Calls 15

ConstFunction · 0.92
MulFunction · 0.92
SumFunction · 0.92
TargetFunction · 0.92
ArgFunction · 0.92
MemberOverloadFunction · 0.92
EvalCostFunction · 0.92
StringScanFunction · 0.92
AtLeastOneQuantityFunction · 0.92
LengthFunction · 0.92
ResultFunction · 0.92
ResultSizeFunction · 0.92

Tested by

no test coverage detected