Your idea, correct me if I misunderstood, is to just switch to the non-SSO way of storing the string like one would do when the string becomes larger than 23 bytes.
Correct me if I’m wrong, but I think you misunderstand me. What I am proposing is that the current as_mut_vec implementation be changed to something like this:
fn as_mut_vec(&mut self) -> &mut Vec<u8> {
if self.is_sso() {
// This method changes the String’s representation to a non-SSO one;
// that is, one using a pointer, length, and capacity.
self.change_from_sso_to_normal_representation();
}
&mut self.vec
}
This would work regardless of how SSO gets implemented.
from_raw_parts is potentially backwards-incompatible to change, but it depends on the precise SSO implementation. Forcing a capacity with a multiple of 2 could be backwards compatible, as the Vec could simply be reallocated whenever the capacity is odd (I think). It’s likely that most other SSO implementations could work with it, too.