I was told that one String optimization shouldn't be done by default because of the number of branches introduced but I think it was SSO, not 'static CoW.
-
-
Replying to @eddyb_r @withoutboats
That's for SSO. 'static COW strings introduce zero branches AFAICT.
1 reply 0 retweets 0 likes -
Replying to @ManishEarth @withoutboats
You need some extra code to copy the current length when first allocating the memory for the string but otherwise I think that's true.
2 replies 0 retweets 0 likes -
-
Replying to @withoutboats @eddyb_r
Change the check in Drop for "is the pointer 0x1" to "Is the capacity zero"
1 reply 0 retweets 1 like -
Replying to @ManishEarth @withoutboats
We check the pointer, not the capacity?!
2 replies 0 retweets 0 likes -
Oh wait, that's because it's `Vec<u8>` isn't it? So none of this is specific to `String`, but rather `Vec<T>` and `&'static [T]`.
1 reply 0 retweets 0 likes -
Replying to @eddyb_r @ManishEarth
Yea & whether or not to apply this optimization to slice/vec is another debate
1 reply 0 retweets 1 like -
Replying to @withoutboats @ManishEarth
IMO we should, anything that makes `Vec<u8>` worse is sad, strings aren't *that* special.
1 reply 0 retweets 3 likes -
It also means you don't have to pull out all the `Vec<u8>` innards, or hack around them, to do it.
1 reply 0 retweets 0 likes
Another problem with this optimization is that `index_mut` and `deref_mut` would need an additional check, incurring some performance cost. That's probably acceptable for `String`, but a bit concerning for `Vec<T>`, I think...
-
-
Some sibling subthread (which, good luck finding it, lol twitter thread navigation) has that realization as well, heh. I think @Gankro mentioned something about methods which mutate existing contents and that's when the penny dropped.
1 reply 0 retweets 0 likes -
Yeah. Conveniently the `ptr + len` repr lets all truncation methods avoid COW. String::pop? Ok len--, good to go.
0 replies 0 retweets 3 likes
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.