]> Cypherpunks repositories - gostls13.git/commit
strings: align Clone output with string([]byte(""))
authorMartin Möhrmann <martin@golang.org>
Mon, 1 Nov 2021 05:42:01 +0000 (06:42 +0100)
committerMartin Möhrmann <martin@golang.org>
Mon, 1 Nov 2021 14:45:28 +0000 (14:45 +0000)
commit82f902ae8e2b7f7eff0cdb087e47e939cc296a62
tree90fdfdaacdb208e39bcbb9efbe4a5b0e5fe72944
parent4056934e483c51fa046f9c2d1ee35f0385b84d91
strings: align Clone output with string([]byte(""))

Add a comment how strings of length 0 are treated and
that they always will result in the return of a string
equal to the constant string "".

The previous implementation would return a string header that uses
runtime.zerobase as the backing array pointer while the string constant
"" has 0 as pointer value.

Using 0 has the backing array pointer is also the behaviour of
string([]byte(input)) which makes the new behaviour a better drop in
replacement.

Change-Id: Ic5460e9494b6708edbdfa4361e878d50db54ba10
Reviewed-on: https://go-review.googlesource.com/c/go/+/360255
Trust: Martin Möhrmann <martin@golang.org>
Run-TryBot: Martin Möhrmann <martin@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/strings/clone.go
src/strings/clone_test.go