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

Function trackStringReplaceCost

ext/strings.go:1055–1067  ·  view source on GitHub ↗

trackStringReplaceCost tracks runtime cost for string replace operations, accounting for search cost and the size of the result.

(args []ref.Val, result ref.Val)

Source from the content-addressed store, hash-verified

1053// trackStringReplaceCost tracks runtime cost for string replace operations,
1054// accounting for search cost and the size of the result.
1055func trackStringReplaceCost(args []ref.Val, result ref.Val) *uint64 {
1056 targetSize := actualSize(args[0])
1057 if targetSize == 0 {
1058 targetSize = 1
1059 }
1060 needleSize := actualSize(args[1])
1061 if needleSize == 0 {
1062 needleSize = 1
1063 }
1064 searchCost := uint64(math.Ceil(float64(targetSize*needleSize) * stringCostFactor))
1065 cost := safeAdd(callCost, searchCost, actualSize(result))
1066 return &cost
1067}
1068
1069// trackStringSplitCost tracks runtime cost for string split operations,
1070// accounting for traversal and list allocation.

Callers

nothing calls this directly

Calls 2

safeAddFunction · 0.85
actualSizeFunction · 0.70

Tested by

no test coverage detected