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

func s2s use deprecated code in golang 1.20 #99

Open
TomasVojacek opened this issue Oct 16, 2023 · 0 comments
Open

func s2s use deprecated code in golang 1.20 #99

TomasVojacek opened this issue Oct 16, 2023 · 0 comments

Comments

@TomasVojacek
Copy link

Same problem has been solved in fasthttp in valyala/fasthttp#1481
Original code:
func s2b(s string) (b []byte) {
strh := (*reflect.StringHeader)(unsafe.Pointer(&s))
sh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sh.Data = strh.Data
sh.Len = strh.Len
sh.Cap = strh.Len
return b
}

Was replaced in b2s_new.go
// s2b converts string to a byte slice without memory allocation.
func s2b(s string) []byte {
return unsafe.Slice(unsafe.StringData(s), len(s))
}

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