Skip to content

Commit e04f74b

Browse files
crazycs520zz-jason
authored andcommitted
chunk: reduce chunk's iterator function call (#7585)
1 parent 3d891d9 commit e04f74b

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

util/chunk/iterator.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,15 @@ func NewIterator4Chunk(chk *Chunk) *Iterator4Chunk {
105105

106106
// Iterator4Chunk is used to iterate rows inside a chunk.
107107
type Iterator4Chunk struct {
108-
chk *Chunk
109-
cursor int
108+
chk *Chunk
109+
cursor int32
110+
numRows int32
110111
}
111112

112113
// Begin implements the Iterator interface.
113114
func (it *Iterator4Chunk) Begin() Row {
114-
if it.chk.NumRows() == 0 {
115+
it.numRows = int32(it.chk.NumRows())
116+
if it.numRows == 0 {
115117
return it.End()
116118
}
117119
it.cursor = 1
@@ -120,21 +122,21 @@ func (it *Iterator4Chunk) Begin() Row {
120122

121123
// Next implements the Iterator interface.
122124
func (it *Iterator4Chunk) Next() Row {
123-
if it.cursor >= it.chk.NumRows() {
124-
it.cursor = it.chk.NumRows() + 1
125+
if it.cursor >= it.numRows {
126+
it.cursor = it.numRows + 1
125127
return it.End()
126128
}
127-
row := it.chk.GetRow(it.cursor)
129+
row := it.chk.GetRow(int(it.cursor))
128130
it.cursor++
129131
return row
130132
}
131133

132134
// Current implements the Iterator interface.
133135
func (it *Iterator4Chunk) Current() Row {
134-
if it.cursor == 0 || it.cursor > it.Len() {
136+
if it.cursor == 0 || int(it.cursor) > it.Len() {
135137
return it.End()
136138
}
137-
return it.chk.GetRow(it.cursor - 1)
139+
return it.chk.GetRow(int(it.cursor) - 1)
138140
}
139141

140142
// End implements the Iterator interface.
@@ -144,7 +146,7 @@ func (it *Iterator4Chunk) End() Row {
144146

145147
// ReachEnd implements the Iterator interface.
146148
func (it *Iterator4Chunk) ReachEnd() {
147-
it.cursor = it.Len() + 1
149+
it.cursor = int32(it.Len() + 1)
148150
}
149151

150152
// Len implements the Iterator interface

0 commit comments

Comments
 (0)