Skip to content

Commit 9c39977

Browse files
authored
chunk: use native go style to do initialization (pingcap#11242)
1 parent c8ed781 commit 9c39977

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

util/chunk/chunk.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,16 @@ func NewChunkWithCapacity(fields []*types.FieldType, cap int) *Chunk {
5555
// cap: the limit for the max number of rows.
5656
// maxChunkSize: the max limit for the number of rows.
5757
func New(fields []*types.FieldType, cap, maxChunkSize int) *Chunk {
58-
chk := new(Chunk)
59-
chk.columns = make([]*column, 0, len(fields))
60-
chk.capacity = mathutil.Min(cap, maxChunkSize)
58+
chk := &Chunk{
59+
columns: make([]*column, 0, len(fields)),
60+
capacity: mathutil.Min(cap, maxChunkSize),
61+
// set the default value of requiredRows to maxChunkSize to let chk.IsFull() behave
62+
// like how we judge whether a chunk is full now, then the statement
63+
// "chk.NumRows() < maxChunkSize"
64+
// equals to "!chk.IsFull()".
65+
requiredRows: maxChunkSize,
66+
}
67+
6168
for _, f := range fields {
6269
elemLen := getFixedLen(f)
6370
if elemLen == varElemLen {
@@ -66,14 +73,7 @@ func New(fields []*types.FieldType, cap, maxChunkSize int) *Chunk {
6673
chk.columns = append(chk.columns, newFixedLenColumn(elemLen, chk.capacity))
6774
}
6875
}
69-
chk.numVirtualRows = 0
70-
71-
// set the default value of requiredRows to maxChunkSize to let chk.IsFull() behave
72-
// like how we judge whether a chunk is full now, then the statement
73-
// "chk.NumRows() < maxChunkSize"
74-
// is equal to
75-
// "!chk.IsFull()".
76-
chk.requiredRows = maxChunkSize
76+
7777
return chk
7878
}
7979

0 commit comments

Comments
 (0)