diff options
Diffstat (limited to 'src/strings/clone.go')
| -rw-r--r-- | src/strings/clone.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/strings/clone.go b/src/strings/clone.go index 6097c6cc88..edd1497d9e 100644 --- a/src/strings/clone.go +++ b/src/strings/clone.go @@ -16,7 +16,12 @@ import ( // overuse of Clone can make programs use more memory. // Clone should typically be used only rarely, and only when // profiling indicates that it is needed. +// For strings of length zero the string "" will be returned +// and no allocation is made. func Clone(s string) string { + if len(s) == 0 { + return "" + } b := make([]byte, len(s)) copy(b, s) return *(*string)(unsafe.Pointer(&b)) |
