From 28ebbd9bf1300bc7d763a0f02facad70ee60190f Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Sun, 15 Jun 2025 12:14:07 +0900 Subject: [PATCH] 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. --- b2s_new.go => b2s.go | 2 -- b2s_old.go | 14 -------------- fasthttpadaptor/{b2s_new.go => b2s.go} | 2 -- fasthttpadaptor/b2s_old.go | 14 -------------- s2b_new.go => s2b.go | 2 -- s2b_old.go | 21 --------------------- 6 files changed, 55 deletions(-) rename b2s_new.go => b2s.go (93%) delete mode 100644 b2s_old.go rename fasthttpadaptor/{b2s_new.go => b2s.go} (93%) delete mode 100644 fasthttpadaptor/b2s_old.go rename s2b_new.go => s2b.go (90%) delete mode 100644 s2b_old.go diff --git a/b2s_new.go b/b2s.go similarity index 93% rename from b2s_new.go rename to b2s.go index a45222c..24ba337 100644 --- a/b2s_new.go +++ b/b2s.go @@ -1,5 +1,3 @@ -//go:build go1.20 - package fasthttp import "unsafe" diff --git a/b2s_old.go b/b2s_old.go deleted file mode 100644 index f6e9466..0000000 --- a/b2s_old.go +++ /dev/null @@ -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)) -} diff --git a/fasthttpadaptor/b2s_new.go b/fasthttpadaptor/b2s.go similarity index 93% rename from fasthttpadaptor/b2s_new.go rename to fasthttpadaptor/b2s.go index 6246e30..ec8dcbc 100644 --- a/fasthttpadaptor/b2s_new.go +++ b/fasthttpadaptor/b2s.go @@ -1,5 +1,3 @@ -//go:build go1.20 - package fasthttpadaptor import "unsafe" diff --git a/fasthttpadaptor/b2s_old.go b/fasthttpadaptor/b2s_old.go deleted file mode 100644 index a025198..0000000 --- a/fasthttpadaptor/b2s_old.go +++ /dev/null @@ -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)) -} diff --git a/s2b_new.go b/s2b.go similarity index 90% rename from s2b_new.go rename to s2b.go index aedc448..2659264 100644 --- a/s2b_new.go +++ b/s2b.go @@ -1,5 +1,3 @@ -//go:build go1.20 - package fasthttp import "unsafe" diff --git a/s2b_old.go b/s2b_old.go deleted file mode 100644 index 50a034b..0000000 --- a/s2b_old.go +++ /dev/null @@ -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 -}