chore(internal): remove duplicate safe & unsafe

This commit is contained in:
jianghang 2022-08-02 00:05:40 +08:00
parent ce016ed85f
commit b50b1c8f7a
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)},
))
}