3 ms·
I never heard of "German strings" in place of the small string optimization before! And there had been way too many proposals to add such types to the standard
by lifthrasiir 2y ago
I never heard of "German strings" in place of the small string optimization before! And there had been way too many proposals to add such types to the standard library [1] [2] [3] [4]. My understanding is that:
1. Both `Vec<u8>` and `String` should share the same layout as part of the standard library's contract.
2. Unlike `String`, the equivalent optimization for `Vec<T>` is more questionable especially when T might be any type. C++ standard libraries frequently do implement multiple layouts for std::string but not for std::vector<T> for the same reason.
3. Rust never allows an implicit copying of `String` in the first place, which greatly benefits from the SSO, so the lack of SSO in Rust is less important compared to C++.
[1] https://github.com/rust-lang/rust/issues/4991 https://github.com/rust-lang/rust/issues/4991
[2] https://github.com/rust-lang/rust/issues/20198 https://github.com/rust-lang/rust/issues/20198
[3] https://github.com/rust-lang/rfcs/pull/2990 https://github.com/rust-lang/rfcs/pull/2990
[4] https://github.com/rust-lang/unsafe-code-guidelines/issues/499 https://github.com/rust-lang/unsafe-code-guidelines/issues/4...