Skip to content

Add AppendSkip method that does not allocate new slice #372

Closed
@ernado

Description

@ernado

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions