Commit 3eeedea 1 parent 3a4b1f0 commit 3eeedea Copy full SHA for 3eeedea
File tree 1 file changed +5
-7
lines changed
1 file changed +5
-7
lines changed Original file line number Diff line number Diff line change
1
+ //go:build !js
1
2
// +build !js
3
+
2
4
// Copyright (c) Roman Atachiants and contributors. All rights reserved.
3
5
// Licensed under the MIT license. See LICENSE file in the project root for details.
4
6
@@ -15,15 +17,11 @@ func ToString(b *[]byte) string {
15
17
}
16
18
17
19
// ToBytes converts a string to a byte slice without allocating.
18
- func ToBytes (v string ) ( b []byte ) {
20
+ func ToBytes (v string ) []byte {
19
21
strHeader := (* reflect .StringHeader )(unsafe .Pointer (& v ))
20
- byteHeader := (* reflect .SliceHeader )(unsafe .Pointer (& b ))
21
- byteHeader .Data = strHeader .Data
22
+ bytesData := unsafe .Slice ((* byte )(unsafe .Pointer (strHeader .Data )), len (v ))
22
23
23
- l := len (v )
24
- byteHeader .Len = l
25
- byteHeader .Cap = l
26
- return
24
+ return bytesData
27
25
}
28
26
29
27
func binaryToBools (b * []byte ) []bool {
You can’t perform that action at this time.
0 commit comments