MCPcopy
hub / github.com/pingcap/tidb / preRealloc

Function preRealloc

pkg/util/codec/codec.go:64–87  ·  view source on GitHub ↗
(b []byte, vals []types.Datum, comparable1 bool)

Source from the content-addressed store, hash-verified

62)
63
64func preRealloc(b []byte, vals []types.Datum, comparable1 bool) []byte {
65 var size int
66 for i := range vals {
67 switch vals[i].Kind() {
68 case types.KindInt64, types.KindUint64, types.KindMysqlEnum, types.KindMysqlSet, types.KindMysqlBit, types.KindBinaryLiteral:
69 size += sizeInt(comparable1)
70 case types.KindString, types.KindBytes:
71 size += sizeBytes(vals[i].GetBytes(), comparable1)
72 case types.KindMysqlTime, types.KindMysqlDuration, types.KindFloat32, types.KindFloat64:
73 size += 9
74 case types.KindNull, types.KindMinNotNull, types.KindMaxValue:
75 size++
76 case types.KindMysqlJSON:
77 size += 2 + len(vals[i].GetBytes())
78 case types.KindVectorFloat32:
79 size += 1 + vals[i].GetVectorFloat32().SerializedSize()
80 case types.KindMysqlDecimal:
81 size += 1 + types.MyDecimalStructSize
82 default:
83 return b
84 }
85 }
86 return reallocBytes(b, size)
87}
88
89// encode will encode a datum and append it to a byte slice. If comparable1 is true, the encoded bytes can be sorted as it's original order.
90// If hash is true, the encoded bytes can be checked equal as it's original value.

Callers 1

encodeFunction · 0.85

Calls 7

sizeIntFunction · 0.85
sizeBytesFunction · 0.85
SerializedSizeMethod · 0.80
reallocBytesFunction · 0.70
KindMethod · 0.45
GetBytesMethod · 0.45
GetVectorFloat32Method · 0.45

Tested by

no test coverage detected