Skip to content

Commit ef211bd

Browse files
Only calculate isVectorVariableLengthType once and reuse
1 parent 1579369 commit ef211bd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

marshal.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,12 +836,13 @@ func marshalVector(info VectorType, value interface{}) ([]byte, error) {
836836
return nil, marshalErrorf("expected vector with %d dimensions, received %d", info.Dimensions, n)
837837
}
838838

839+
isLengthType := isVectorVariableLengthType(info.SubType)
839840
for i := 0; i < n; i++ {
840841
item, err := Marshal(info.SubType, rv.Index(i).Interface())
841842
if err != nil {
842843
return nil, err
843844
}
844-
if isVectorVariableLengthType(info.SubType) {
845+
if isLengthType {
845846
writeUnsignedVInt(buf, uint64(len(item)))
846847
}
847848
buf.Write(item)
@@ -889,9 +890,10 @@ func unmarshalVector(info VectorType, data []byte, value interface{}) error {
889890
}
890891
}
891892
elemSize := len(data) / info.Dimensions
893+
isLengthType := isVectorVariableLengthType(info.SubType)
892894
for i := 0; i < info.Dimensions; i++ {
893895
offset := 0
894-
if isVectorVariableLengthType(info.SubType) {
896+
if isLengthType {
895897
m, p, err := readUnsignedVInt(data)
896898
if err != nil {
897899
return err

0 commit comments

Comments
 (0)