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

Function doublingStringBindExpr

ext/bindings_test.go:433–439  ·  view source on GitHub ↗

doublingStringBindExpr doubles the input string s through nested cel.bind calls: cel.bind(a0, s, cel.bind(a1, a0 + a0, ... cel.bind(aN, aN-1 + aN-1, aN == aN))) Unlike list concatenation, string concatenation materializes a new backing string at each level, so the physical allocation doubles alon

(levels int)

Source from the content-addressed store, hash-verified

431// Unlike list concatenation, string concatenation materializes a new backing string at each
432// level, so the physical allocation doubles alongside the logical size.
433func doublingStringBindExpr(levels int) string {
434 expr := fmt.Sprintf("a%d == a%d", levels, levels)
435 for i := levels; i >= 1; i-- {
436 expr = fmt.Sprintf("cel.bind(a%d, a%d + a%d, %s)", i, i-1, i-1, expr)
437 }
438 return fmt.Sprintf("cel.bind(a0, s, %s)", expr)
439}
440
441func TestBindingsMemoryLimitStringConcat(t *testing.T) {
442 // A 1MiB input string doubled per bind level. The doublings rapidly exceed the 1M unit

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected