Skip to content

Commit

Permalink
Merge pull request #64 from Fenny/master
Browse files Browse the repository at this point in the history
Improve UnsafeBytes with Go 1.20+
  • Loading branch information
Fenny authored Feb 9, 2024
2 parents e94f26a + aef9a9c commit 230c181
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
9 changes: 1 addition & 8 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,8 @@ func UnsafeString(b []byte) string {

// #nosec G103
// UnsafeBytes returns a byte pointer without allocation.
// String length shouldn't be more than 2147418112.
func UnsafeBytes(s string) []byte {
if s == "" {
return nil
}

return (*[MaxStringLen]byte)(unsafe.Pointer(
(*reflect.StringHeader)(unsafe.Pointer(&s)).Data),
)[:len(s):len(s)]
return unsafe.Slice(unsafe.StringData(s), len(s))
}

// CopyString copies a string to make it immutable
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gofiber/utils/v2

go 1.19
go 1.21

require (
github.com/google/uuid v1.6.0
Expand Down

0 comments on commit 230c181

Please sign in to comment.