Skip to content

Commit 119dde2

Browse files
committed
🧑‍💻 Unsafe: cleanup
1 parent ea2107e commit 119dde2

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

convert.go

+2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ import (
1313
"unsafe"
1414
)
1515

16+
// #nosec G103
1617
// UnsafeString returns a string pointer without allocation
1718
func UnsafeString(b []byte) string {
1819
// the new way is slower `return unsafe.String(unsafe.SliceData(b), len(b))`
1920
// unsafe.Pointer variant: 0.5410 ns/op vs unsafe.String variant: 0.3538 ns/op
2021
return *(*string)(unsafe.Pointer(&b))
2122
}
2223

24+
// #nosec G103
2325
// UnsafeBytes returns a byte pointer without allocation.
2426
func UnsafeBytes(s string) []byte {
2527
return unsafe.Slice(unsafe.StringData(s), len(s))

0 commit comments

Comments
 (0)