3 ms·
It is probably the case in other languages though (I believe — though I'm open to being wrong — it is in Go, string slicing is implemented through array slicing
by masklinn 12y ago
It is probably the case in other languages though (I believe — though I'm open to being wrong — it is in Go, string slicing is implemented through array slicing, so a substring will share the parent string's storage and keep it alive).
- deleted 12y ago[deleted]
- masklinn 12y ago> substrings are mutable Are you sure? I know that a byte slice []byte is mutable, but I thought slicing a string yielded a string (and strings are immutable), an explicit conversion (and copy) is needed to get the underlying byte slice.
- pcwalton 12y agoOh yes, my mistake, they're immutable. I was thinking of []byte.