-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new
unsafe
functions introduced in go 1.20
This eliminates usage of deprecated and error prone `reflect.SliceHeader` and `reflect.StringHeader`. Backwards compatibility saved with build tags
- Loading branch information
Showing
3 changed files
with
17 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
//go:build !purego | ||
// +build !purego | ||
//go:build !purego && !go1.20 | ||
// +build !purego,!go1.20 | ||
|
||
package ws | ||
|
||
|
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,14 @@ | ||
//go:build !purego && go1.20 | ||
// +build !purego,go1.20 | ||
|
||
package ws | ||
|
||
import "unsafe" | ||
|
||
func strToBytes(str string) (bts []byte) { | ||
return unsafe.Slice(unsafe.StringData(str), len(str)) | ||
} | ||
|
||
func btsToString(bts []byte) (str string) { | ||
return unsafe.String(&bts[0], len(bts)) | ||
} |
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