mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-23 12:00:39 +08:00
优化代码结构
This commit is contained in:
20
helper.go
Normal file
20
helper.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package docxlib
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// BytesToString 没有内存开销的转换
|
||||
func BytesToString(b []byte) string {
|
||||
return *(*string)(unsafe.Pointer(&b))
|
||||
}
|
||||
|
||||
// StringToBytes 没有内存开销的转换
|
||||
func StringToBytes(s string) (b []byte) {
|
||||
bh := (*slice)(unsafe.Pointer(&b))
|
||||
sh := (*slice)(unsafe.Pointer(&s))
|
||||
bh.data = sh.data
|
||||
bh.len = sh.len
|
||||
bh.cap = sh.len
|
||||
return b
|
||||
}
|
||||
Reference in New Issue
Block a user