Skip to content

rlp: return Iterator as non-pointer#2653

Merged
ucwong merged 1 commit into
masterfrom
dev
Feb 19, 2026
Merged

rlp: return Iterator as non-pointer#2653
ucwong merged 1 commit into
masterfrom
dev

Conversation

@ucwong
Copy link
Copy Markdown
Member

@ucwong ucwong commented Feb 19, 2026

Most uses of the iterator are like this:

it, _ := rlp.NewListIterator(data)
for it.Next() {
    do(it.Value())
}

This doesn't require the iterator to be a pointer and it's better to have it stack-allocated. AFAIK the compiler cannot prove it is OK to stack-allocate when it is returned as a pointer because the methods of Iterator use pointer receiver and also mutate the object.

The iterator type was not exported until very recently, so I think it is still OK to change this API.

Most uses of the iterator are like this:

    it, _ := rlp.NewListIterator(data)
    for it.Next() {
        do(it.Value())
    }

This doesn't require the iterator to be a pointer and it's better to
have it stack-allocated. AFAIK the compiler cannot prove it is OK to
stack-allocate when it is returned as a pointer because the methods of
`Iterator` use pointer receiver and also mutate the object.

The iterator type was not exported until very recently, so I think it is
still OK to change this API.
@ucwong ucwong marked this pull request as ready for review February 19, 2026 10:11
@ucwong ucwong merged commit a8ae3ba into master Feb 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants