We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ea2107e commit 119dde2Copy full SHA for 119dde2
convert.go
@@ -13,13 +13,15 @@ import (
13
"unsafe"
14
)
15
16
+// #nosec G103
17
// UnsafeString returns a string pointer without allocation
18
func UnsafeString(b []byte) string {
19
// the new way is slower `return unsafe.String(unsafe.SliceData(b), len(b))`
20
// unsafe.Pointer variant: 0.5410 ns/op vs unsafe.String variant: 0.3538 ns/op
21
return *(*string)(unsafe.Pointer(&b))
22
}
23
24
25
// UnsafeBytes returns a byte pointer without allocation.
26
func UnsafeBytes(s string) []byte {
27
return unsafe.Slice(unsafe.StringData(s), len(s))
0 commit comments