bytesconv.go
This file
Path
internal/bytesconv/bytesconv.go
21 lines · 719 bytes · Go
Last changed by
Not known.
History of this fileTake it
1// Copyright 2023 Gin Core Team. All rights reserved.2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45package bytesconv67import (8 "unsafe"9)1011// StringToBytes converts string to byte slice without a memory allocation.12// For more details, see https://github.com/golang/go/issues/53003#issuecomment-1140276077.13func StringToBytes(s string) []byte {14 return unsafe.Slice(unsafe.StringData(s), len(s))15}1617// BytesToString converts byte slice to string without a memory allocation.18// For more details, see https://github.com/golang/go/issues/53003#issuecomment-1140276077.19func BytesToString(b []byte) string {20 return unsafe.String(unsafe.SliceData(b), len(b))21}