mirror of
https://gitee.com/johng/gf.git
synced 2024-12-04 13:18:01 +08:00
20 lines
595 B
Go
20 lines
595 B
Go
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package gconv
|
|
|
|
import "unsafe"
|
|
|
|
// UnsafeStrToBytes converts string to []byte without memory copy.
|
|
func UnsafeStrToBytes(s string) []byte {
|
|
return *(*[]byte)(unsafe.Pointer(&s))
|
|
}
|
|
|
|
// UnsafeBytesToStr converts []byte to string without memory copy.
|
|
func UnsafeBytesToStr(b []byte) string {
|
|
return *(*string)(unsafe.Pointer(&b))
|
|
}
|