-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update unsafe code to user newer-faster-better idioms
- Loading branch information
Showing
2 changed files
with
20 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//go:build !appengine && !js && go1.21 | ||
// +build !appengine,!js,go1.21 | ||
|
||
package util | ||
|
||
import ( | ||
"unsafe" | ||
) | ||
|
||
// BytesToReadOnlyString returns a string converted from given bytes. | ||
func BytesToReadOnlyString(b []byte) string { | ||
return unsafe.String(unsafe.SliceData(b), len(b)) | ||
} | ||
|
||
// StringToReadOnlyBytes returns bytes converted from given string. | ||
func StringToReadOnlyBytes(s string) []byte { | ||
return unsafe.Slice(unsafe.StringData(s), len(s)) | ||
} |