Merge pull request #2174 from j178/master

Remove duplicate safe & unsafe
This commit is contained in:
Vladimir Mihailenco 2022-08-02 08:50:01 +03:00 committed by GitHub
commit 084c0c8914
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 35 deletions

View File

@ -104,7 +104,7 @@ func cmdString(cmd Cmder, val interface{}) string {
b = internal.AppendArg(b, val) b = internal.AppendArg(b, val)
} }
return internal.String(b) return util.BytesToString(b)
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@ -4,6 +4,8 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"time" "time"
"github.com/go-redis/redis/v9/internal/util"
) )
func AppendArg(b []byte, v interface{}) []byte { func AppendArg(b []byte, v interface{}) []byte {
@ -11,7 +13,7 @@ func AppendArg(b []byte, v interface{}) []byte {
case nil: case nil:
return append(b, "<nil>"...) return append(b, "<nil>"...)
case string: case string:
return appendUTF8String(b, Bytes(v)) return appendUTF8String(b, util.StringToBytes(v))
case []byte: case []byte:
return appendUTF8String(b, v) return appendUTF8String(b, v)
case int: case int:

View File

@ -1,12 +0,0 @@
//go:build appengine
// +build appengine
package internal
func String(b []byte) string {
return string(b)
}
func Bytes(s string) []byte {
return []byte(s)
}

View File

@ -1,21 +0,0 @@
//go:build !appengine
// +build !appengine
package internal
import "unsafe"
// String converts byte slice to string.
func String(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
// Bytes converts string to byte slice.
func Bytes(s string) []byte {
return *(*[]byte)(unsafe.Pointer(
&struct {
string
Cap int
}{s, len(s)},
))
}