From b50b1c8f7aaccc257dca477209d74d4cd2cbef80 Mon Sep 17 00:00:00 2001 From: jianghang Date: Tue, 2 Aug 2022 00:05:40 +0800 Subject: [PATCH] chore(internal): remove duplicate safe & unsafe --- command.go | 2 +- internal/arg.go | 4 +++- internal/safe.go | 12 ------------ internal/unsafe.go | 21 --------------------- 4 files changed, 4 insertions(+), 35 deletions(-) delete mode 100644 internal/safe.go delete mode 100644 internal/unsafe.go diff --git a/command.go b/command.go index 319bfba..cb1f26a 100644 --- a/command.go +++ b/command.go @@ -104,7 +104,7 @@ func cmdString(cmd Cmder, val interface{}) string { b = internal.AppendArg(b, val) } - return internal.String(b) + return util.BytesToString(b) } //------------------------------------------------------------------------------ diff --git a/internal/arg.go b/internal/arg.go index b97fa0d..af5f8c9 100644 --- a/internal/arg.go +++ b/internal/arg.go @@ -4,6 +4,8 @@ import ( "fmt" "strconv" "time" + + "github.com/go-redis/redis/v9/internal/util" ) func AppendArg(b []byte, v interface{}) []byte { @@ -11,7 +13,7 @@ func AppendArg(b []byte, v interface{}) []byte { case nil: return append(b, ""...) case string: - return appendUTF8String(b, Bytes(v)) + return appendUTF8String(b, util.StringToBytes(v)) case []byte: return appendUTF8String(b, v) case int: diff --git a/internal/safe.go b/internal/safe.go deleted file mode 100644 index fd2f434..0000000 --- a/internal/safe.go +++ /dev/null @@ -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) -} diff --git a/internal/unsafe.go b/internal/unsafe.go deleted file mode 100644 index 9f2e418..0000000 --- a/internal/unsafe.go +++ /dev/null @@ -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)}, - )) -}