-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: updated to v2 & simplified calling
- Loading branch information
Showing
5 changed files
with
21 additions
and
21 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module github.com/AH-dark/bytestring | ||
module github.com/AH-dark/bytestring/v2 | ||
|
||
go 1.21 | ||
|
||
|
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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
//go:build go1.20 || go1.21 || go1.22 | ||
// +build go1.20 go1.21 go1.22 | ||
|
||
package bytestring | ||
package bs | ||
|
||
import "unsafe" | ||
|
||
// StringToBytes converts string to byte slice without a memory allocation. | ||
// S2B converts string to byte slice without a memory allocation. | ||
// For more details, see https://github.com/golang/go/issues/53003#issuecomment-1140276077. | ||
func StringToBytes(s string) []byte { | ||
func S2B(s string) []byte { | ||
return unsafe.Slice(unsafe.StringData(s), len(s)) | ||
} | ||
|
||
// BytesToString converts byte slice to string without a memory allocation. | ||
// B2S converts byte slice to string without a memory allocation. | ||
// For more details, see https://github.com/golang/go/issues/53003#issuecomment-1140276077. | ||
func BytesToString(b []byte) string { | ||
func B2S(b []byte) string { | ||
return unsafe.String(unsafe.SliceData(b), len(b)) | ||
} |