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 1 commit
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
12 changes: 7 additions & 5 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 int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the type from int to int32 to make Iterator4Chunk only take 16 bytes in a 64-bit machine?

numRows int
}

// Begin implements the Iterator interface.
func (it *Iterator4Chunk) Begin() Row {
if it.chk.NumRows() == 0 {
it.numRows = it.chk.NumRows()
if it.numRows == 0 {
Copy link
Contributor

@eurekaka eurekaka Sep 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any use case that we are iterating the chunk while appending into it simultaneously? I guess this is not allowed, just to make sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there isn't.

return it.End()
}
it.cursor = 1
Expand All @@ -120,8 +122,8 @@ 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)
Expand Down