]> Cypherpunks repositories - gostls13.git/commitdiff
unique: use stringslite.Clone
authorqiulaidongfeng <2645477756@qq.com>
Sat, 4 May 2024 01:42:30 +0000 (01:42 +0000)
committerGopher Robot <gobot@golang.org>
Sun, 5 May 2024 00:24:21 +0000 (00:24 +0000)
Change-Id: Icb1ba7df1f0414090632e663b6a92b492546070d
GitHub-Last-Rev: 5169d2681311d2631d9119aea17114602efcaa24
GitHub-Pull-Request: golang/go#67092
Reviewed-on: https://go-review.googlesource.com/c/go/+/581940
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Reviewed-by: Keith Randall <khr@google.com>
src/unique/clone.go

index b30d44e393c1e51258c755ce5b23a7d8cffd1a87..36ced14ecea0a4601635f3a46d8825204933f99c 100644 (file)
@@ -6,6 +6,7 @@ package unique
 
 import (
        "internal/abi"
+       "internal/stringslite"
        "unsafe"
 )
 
@@ -20,7 +21,7 @@ import (
 func clone[T comparable](value T, seq *cloneSeq) T {
        for _, offset := range seq.stringOffsets {
                ps := (*string)(unsafe.Pointer(uintptr(unsafe.Pointer(&value)) + offset))
-               *ps = cloneString(*ps)
+               *ps = stringslite.Clone(*ps)
        }
        return value
 }
@@ -86,15 +87,3 @@ func buildArrayCloneSeq(typ *abi.Type, seq *cloneSeq, baseOffset uintptr) {
                offset = (offset + align - 1) &^ (align - 1)
        }
 }
-
-// cloneString is a copy of strings.Clone, because we can't depend on the strings
-// package here. Several packages that might make use of unique, like net, explicitly
-// forbid depending on unicode, which strings depends on.
-func cloneString(s string) string {
-       if len(s) == 0 {
-               return ""
-       }
-       b := make([]byte, len(s))
-       copy(b, s)
-       return unsafe.String(&b[0], len(b))
-}