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

Add AppendSkip method that does not allocate new slice #372

Closed
ernado opened this issue Jun 7, 2019 · 0 comments
Closed

Add AppendSkip method that does not allocate new slice #372

ernado opened this issue Jun 7, 2019 · 0 comments

Comments

@ernado
Copy link
Contributor

ernado commented Jun 7, 2019

We have

// SkipAndReturnBytes skip next JSON element, and return its content as []byte.
// The []byte can be kept, it is a copy of data.
func (iter *Iterator) SkipAndReturnBytes() []byte {
	iter.startCapture(iter.head)
	iter.Skip()
	return
}

I propose something like that:

// AppendSkip skips next JSON element and appends its content to
// buffer, returning the result.
func (iter *Iterator) AppendSkip(buf []byte) []byte {
	return append(buf, iter.SkipAndReturnBytes()...)
}

Obviously, the internal implementation will differ and will not allocate a new slice.
It is like Time.AppendFormat, but for SkipAndReturnBytes.

This will allow allocation optimizations in case of concurrent parsing.

If you are interested in such implementation, I can prepare a PR.

ernado added a commit to ernado/go that referenced this issue Jun 7, 2019
@taowen taowen closed this as completed in 27518f6 Jun 21, 2019
zhenzou pushed a commit to zhenzou/jsoniter that referenced this issue Feb 2, 2022
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

No branches or pull requests

1 participant