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

common: deprecate CopyBytes #31546

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fjl
Copy link
Contributor

@fjl fjl commented Apr 2, 2025

No description provided.

@fjl fjl changed the title common: deprecated CopyBytes common: deprecate CopyBytes Apr 2, 2025
@fjl
Copy link
Contributor Author

fjl commented Apr 2, 2025

I would like to note that bytes.Clone does not have exactly the same semantics as common.CopyBytes, since it is based on append rather than make+copy. The documentation explicitly states that the result "may have additional capacity". We need to carefully evaluate if this can be a problem, since it can lead to a situation where we modify an existing slice when a new one would've been created by a subsequent append operation.

@@ -180,7 +180,7 @@ func (b *memoryBatch) AppendRaw(kind string, number uint64, blob []byte) error {
if b.next[kind] != number {
return errOutOrderInsertion
}
b.data[kind] = append(b.data[kind], common.CopyBytes(blob))
b.data[kind] = append(b.data[kind], bytes.Clone(blob))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This clone seems useless since we are copying the input anyway.

@fjl
Copy link
Contributor Author

fjl commented Apr 2, 2025

We could get the old semantics back if needed by replacing common.CopyBytes(x) with bytes.Clip(bytes.Clone(x)), but it might not be needed in all cases.

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.

3 participants