I assume the underlying storage isn't reference counted, because if it was it seems it would be trivial to detect there's only a single reference left, and trigger a reallocation.
Unless the underlying storage is reference counted with some small granularity. That might be a way to go, when a substring is taken, split the original and keep track of the pieces separately.
talos•3mo ago