-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtools.go
More file actions
41 lines (35 loc) · 779 Bytes
/
Copy pathtools.go
File metadata and controls
41 lines (35 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package fly
import (
"reflect"
"unsafe"
)
/*
IfChanClosed please be carefully if want to use to judge if chan closed
*/
func IfChanClosed[T any](ch chan T) (closed bool) {
return (*(**struct {
_, _ uint
_ unsafe.Pointer
_ uint16
closed uint32
})(unsafe.Pointer(&ch))).closed != 0
}
func QuickStringToBytes(str string) []byte {
return s2b(str)
}
func QuickBytesToString(b []byte) string {
return b2s(b)
}
// b2s thanks for fasthttp s2b_new.go
func b2s(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
// s2b thanks for fasthttp b2s_new.go
func s2b(s string) (b []byte) {
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
bh.Data = sh.Data
bh.Cap = sh.Len
bh.Len = sh.Len
return b
}