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

Use unsafe.string instead of unsafe.pointer #372

Closed
wants to merge 1 commit into from

Conversation

karelbilek
Copy link

This only a cosmetic change, the speed seems to be exactly the same

Closes #371

msgp/unsafe.go Outdated Show resolved Hide resolved
This only a cosmetic change, the speed seems to be exactly the same
@klauspost
Copy link
Collaborator

klauspost commented Oct 10, 2024

len() is not an operation. It is just a value read from register/memory, so you are not gaining anything.

I compared the assembly to the old code, and this always inserts a string length check. https://go.dev/src/runtime/unsafe.go - line 21 against int overflow. Since we have a valid byte slice we don't need this check, and will just add an extra branch to all use.

I suggest we abandon this change.

@karelbilek
Copy link
Author

OK no problem

@karelbilek karelbilek closed this Oct 10, 2024
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.

use unsafe.String
2 participants