Skip to content

Commit d51dae1

Browse files
authored
vector: replace KindOf function with Any.Kind method (#6568)
1 parent 801910a commit d51dae1

29 files changed

+114
-89
lines changed

runtime/vam/expr/arith.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ func (a *Arith) Eval(val vector.Any) vector.Any {
3131
func (a *Arith) eval(vecs ...vector.Any) (out vector.Any) {
3232
lhs := enumToIndex(vector.Under(vecs[0]))
3333
rhs := enumToIndex(vector.Under(vecs[1]))
34-
if k := vector.KindOf(lhs); k == vector.KindNull || k == vector.KindError {
34+
if k := lhs.Kind(); k == vector.KindNull || k == vector.KindError {
3535
return lhs
3636
}
37-
if k := vector.KindOf(rhs); k == vector.KindNull || k == vector.KindError {
37+
if k := rhs.Kind(); k == vector.KindNull || k == vector.KindError {
3838
return rhs
3939
}
4040
lhs, rhs, errVal := coerceVals(a.sctx, lhs, rhs)
4141
if errVal != nil {
4242
return errVal
4343
}
44-
kind := vector.KindOf(lhs)
45-
if kind != vector.KindOf(rhs) {
44+
kind := lhs.Kind()
45+
if kind != rhs.Kind() {
4646
panic(fmt.Sprintf("vector kind mismatch after coerce (%#v and %#v)", lhs, rhs))
4747
}
4848
if kind == vector.KindFloat && a.opCode == vector.ArithMod {

runtime/vam/expr/compare.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ func (c *Compare) eval(vecs ...vector.Any) vector.Any {
4747
return vector.NewConst(super.False, vecs[0].Len(), nulls)
4848
}
4949
//XXX need to handle overflow (see sam)
50-
kind := vector.KindOf(lhs)
51-
if kind != vector.KindOf(rhs) {
50+
kind := lhs.Kind()
51+
if kind != rhs.Kind() {
5252
panic("vector kind mismatch after coerce")
5353
}
5454
switch kind {

runtime/vam/expr/function/math.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ type Log struct {
141141
func (l *Log) Call(args ...vector.Any) vector.Any {
142142
arg := vector.Under(args[0])
143143
if !super.IsNumber(arg.Type().ID()) {
144-
if vector.KindOf(arg) == vector.KindError {
144+
if arg.Kind() == vector.KindError {
145145
return arg
146146
}
147147
return vector.NewWrappedError(l.sctx, "log: not a number", arg)

runtime/vam/expr/function/string.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Concat struct {
1717
func (c *Concat) Call(args ...vector.Any) vector.Any {
1818
args = underAll(args)
1919
for _, arg := range args {
20-
switch vector.KindOf(arg) {
20+
switch arg.Kind() {
2121
case vector.KindError:
2222
return arg
2323
case vector.KindString:

runtime/vam/expr/function/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ type IsErr struct{}
115115

116116
func (IsErr) Call(args ...vector.Any) vector.Any {
117117
vec := vector.Under(args[0])
118-
if vector.KindOf(vec) != vector.KindError {
118+
if vec.Kind() != vector.KindError {
119119
return vector.NewConst(super.False, vec.Len(), bitvec.Zero)
120120
}
121121
nulls := vector.NullsOf(vec)

runtime/vam/expr/index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (i *Index) eval(args ...vector.Any) vector.Any {
2828
this := args[0]
2929
container := vector.Under(i.container.Eval(this))
3030
index := vector.Under(i.index.Eval(this))
31-
switch vector.KindOf(container) {
31+
switch container.Kind() {
3232
case vector.KindArray, vector.KindSet:
3333
return indexArrayOrSet(i.sctx, container, index, i.base1)
3434
case vector.KindRecord:

runtime/vam/expr/logic.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ func orError(err, vec vector.Any) vector.Any {
154154
func evalBool(sctx *super.Context, fn func(...vector.Any) vector.Any, vecs ...vector.Any) vector.Any {
155155
return vector.Apply(false, func(vecs ...vector.Any) vector.Any {
156156
for i, vec := range vecs {
157-
if vec := vector.Under(vec); vec.Type() == super.TypeBool || vector.KindOf(vec) == vector.KindError {
157+
vec := vector.Under(vec)
158+
if k := vec.Kind(); k == vector.KindBool || k == vector.KindError {
158159
vecs[i] = vec
159160
} else {
160161
vecs[i] = vector.NewWrappedError(sctx, "not type bool", vec)

runtime/vam/expr/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewSearch(s string, val super.Value, e Evaluator) Evaluator {
2929
}
3030
eq := NewCompare(super.NewContext() /* XXX */, "==", nil, nil)
3131
vectorPred := func(vec vector.Any) vector.Any {
32-
if net.IsValid() && vector.KindOf(vec) == vector.KindIP {
32+
if net.IsValid() && vec.Kind() == vector.KindIP {
3333
out := vector.NewFalse(vec.Len())
3434
for i := range vec.Len() {
3535
if ip, null := vector.IPValue(vec, i); !null && net.Contains(ip) {

runtime/vam/expr/slice.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (s *sliceExpr) eval(vecs ...vector.Any) vector.Any {
5353
return vector.NewStringError(s.sctx, "slice index is not a number", to.Len())
5454
}
5555
}
56-
switch vector.KindOf(container) {
56+
switch container.Kind() {
5757
case vector.KindArray, vector.KindSet:
5858
return s.evalArrayOrSlice(container, from, to, s.base1)
5959
case vector.KindBytes, vector.KindString:
@@ -116,7 +116,7 @@ func (s *sliceExpr) evalArrayOrSlice(vec, fromVec, toVec vector.Any, base1 bool)
116116
}
117117
var out vector.Any
118118
inner = vector.Pick(inner, innerIndex)
119-
if vector.KindOf(vec) == vector.KindArray {
119+
if vec.Kind() == vector.KindArray {
120120
out = vector.NewArray(vec.Type().(*super.TypeArray), newOffsets, inner, nullsOut)
121121
} else {
122122
out = vector.NewSet(vec.Type().(*super.TypeSet), newOffsets, inner, nullsOut)

vector/any.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
type Any interface {
99
Type() super.Type
10+
Kind() Kind
1011
Len() uint32
1112
Serialize(*scode.Builder, uint32)
1213
}

0 commit comments

Comments
 (0)