Go gives us the built-in copy function to make a copy of a slice's
contents, but it doesn't (to my knowledge) offer anything similar for
strings. This means that in order to copy a substring (and thereby allow
the larger string to be released by the garbage collector once it is no
longer referenced), you have to copy the substring to a byte slice and then
back to a string. This seems less than optimal. It's also kind of ugly.
Is there a faster way to "deep copy" a string that doesn't require
conversion to and from a slice first? Wouldn't a built-in copy function
that accepts a destination string be useful in this regard?
contents, but it doesn't (to my knowledge) offer anything similar for
strings. This means that in order to copy a substring (and thereby allow
the larger string to be released by the garbage collector once it is no
longer referenced), you have to copy the substring to a byte slice and then
back to a string. This seems less than optimal. It's also kind of ugly.
Is there a faster way to "deep copy" a string that doesn't require
conversion to and from a slice first? Wouldn't a built-in copy function
that accepts a destination string be useful in this regard?