MCPcopy Create free account
hub / github.com/brimdata/super / Call

Method Call

runtime/sam/expr/function/len.go:13–42  ·  view source on GitHub ↗
(args []super.Value)

Source from the content-addressed store, hash-verified

11}
12
13func (l *LenFn) Call(args []super.Value) super.Value {
14 val := args[0].Under()
15 var length int
16 switch typ := super.TypeUnder(val.Type()).(type) {
17 case *super.TypeOfNull:
18 case *super.TypeRecord:
19 length = len(typ.Fields)
20 case *super.TypeArray, *super.TypeSet, *super.TypeMap:
21 var err error
22 length, err = val.ContainerLength()
23 if err != nil {
24 panic(err)
25 }
26 case *super.TypeOfString:
27 length = utf8.RuneCount(val.Bytes())
28 case *super.TypeOfBytes, *super.TypeOfIP, *super.TypeOfNet:
29 length = len(val.Bytes())
30 case *super.TypeError:
31 return l.sctx.WrapError("len()", val)
32 case *super.TypeOfType:
33 t, err := l.sctx.LookupByValue(val.Bytes())
34 if err != nil {
35 return l.sctx.NewError(err)
36 }
37 length = TypeLength(t)
38 default:
39 return l.sctx.WrapError("len: bad type", val)
40 }
41 return super.NewInt64(int64(length))
42}
43
44func TypeLength(typ super.Type) int {
45 switch typ := typ.(type) {

Callers

nothing calls this directly

Calls 10

TypeUnderFunction · 0.92
NewInt64Function · 0.92
TypeLengthFunction · 0.85
UnderMethod · 0.80
ContainerLengthMethod · 0.80
WrapErrorMethod · 0.80
LookupByValueMethod · 0.80
NewErrorMethod · 0.80
TypeMethod · 0.65
BytesMethod · 0.45

Tested by

no test coverage detected