You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-library/vendor/github.com/gin-gonic/gin/internal/bytesconv/bytesconv_1.20.go

24 lines
738 B

11 months ago
// Copyright 2023 Gin Core Team. All rights reserved.
2 years ago
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
11 months ago
//go:build go1.20
2 years ago
package bytesconv
import (
"unsafe"
)
// StringToBytes converts string to byte slice without a memory allocation.
11 months ago
// For more details, see https://github.com/golang/go/issues/53003#issuecomment-1140276077.
2 years ago
func StringToBytes(s string) []byte {
11 months ago
return unsafe.Slice(unsafe.StringData(s), len(s))
2 years ago
}
// BytesToString converts byte slice to string without a memory allocation.
11 months ago
// For more details, see https://github.com/golang/go/issues/53003#issuecomment-1140276077.
2 years ago
func BytesToString(b []byte) string {
11 months ago
return unsafe.String(unsafe.SliceData(b), len(b))
2 years ago
}