Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chunk: reduce chunk's iterator function call #7585

Merged
merged 3 commits into from
Sep 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions util/chunk/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ func NewIterator4Chunk(chk *Chunk) *Iterator4Chunk {

// Iterator4Chunk is used to iterate rows inside a chunk.
type Iterator4Chunk struct {
chk *Chunk
cursor int
chk *Chunk
cursor int32
numRows int32
}

// Begin implements the Iterator interface.
func (it *Iterator4Chunk) Begin() Row {
if it.chk.NumRows() == 0 {
it.numRows = int32(it.chk.NumRows())
if it.numRows == 0 {
return it.End()
}
it.cursor = 1
Expand All @@ -120,21 +122,21 @@ func (it *Iterator4Chunk) Begin() Row {

// Next implements the Iterator interface.
func (it *Iterator4Chunk) Next() Row {
if it.cursor >= it.chk.NumRows() {
it.cursor = it.chk.NumRows() + 1
if it.cursor >= it.numRows {
it.cursor = it.numRows + 1
return it.End()
}
row := it.chk.GetRow(it.cursor)
row := it.chk.GetRow(int(it.cursor))
it.cursor++
return row
}

// Current implements the Iterator interface.
func (it *Iterator4Chunk) Current() Row {
if it.cursor == 0 || it.cursor > it.Len() {
if it.cursor == 0 || int(it.cursor) > it.Len() {
return it.End()
}
return it.chk.GetRow(it.cursor - 1)
return it.chk.GetRow(int(it.cursor) - 1)
}

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

// ReachEnd implements the Iterator interface.
func (it *Iterator4Chunk) ReachEnd() {
it.cursor = it.Len() + 1
it.cursor = int32(it.Len() + 1)
}

// Len implements the Iterator interface
Expand Down