Drop support before go1.20 (#2022)

We still had old implementations of s2b and b2s that didn't require
unsafe.StringData and unsafe.SliceData that were added in go1.20. Since
we don't support go1.20 anymore we can drop these functions.
This commit is contained in:
Erik Dubbelboer
2025-06-15 12:14:07 +09:00
committed by GitHub
parent 75d2192d37
commit 28ebbd9bf1
6 changed files with 0 additions and 55 deletions
-2
View File
@@ -1,5 +1,3 @@
//go:build go1.20
package fasthttp
import "unsafe"
-14
View File
@@ -1,14 +0,0 @@
//go:build !go1.20
package fasthttp
import "unsafe"
// b2s converts byte slice to a string without memory allocation.
// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
//
// Note it may break if string and/or slice header will change
// in the future go versions.
func b2s(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
@@ -1,5 +1,3 @@
//go:build go1.20
package fasthttpadaptor
import "unsafe"
-14
View File
@@ -1,14 +0,0 @@
//go:build !go1.20
package fasthttpadaptor
import "unsafe"
// b2s converts byte slice to a string without memory allocation.
// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
//
// Note it may break if string and/or slice header will change
// in the future go versions.
func b2s(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
-2
View File
@@ -1,5 +1,3 @@
//go:build go1.20
package fasthttp
import "unsafe"
-21
View File
@@ -1,21 +0,0 @@
//go:build !go1.20
package fasthttp
import (
"reflect"
"unsafe"
)
// s2b converts string to a byte slice without memory allocation.
//
// Note it may break if string and/or slice header will change
// in the future go versions.
func s2b(s string) (b []byte) {
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
bh.Data = sh.Data
bh.Cap = sh.Len
bh.Len = sh.Len
return b
}