This program:
package main
import (
"fmt"
"strings"
)
func main() {
var b1 strings.Builder
b1.Grow(3)
b2 := b1
b1.WriteString("foo")
s := b1.String()
fmt.Printf("string before patching: %#v\n", s)
b2.WriteString("bar")
fmt.Printf("string after patching: %#v\n", s)
}
Prints:
string before patching: "foo"
string after patching: "bar"
I think another level of indirection is needed in the implementation, so that the internal buffer is shared even after a copy has been made.
This program:
Prints:
I think another level of indirection is needed in the implementation, so that the internal buffer is shared even after a copy has been made.