Re:Small Strings in Rust: smolstr vs. smartstring
by hummingly on Saturday August 24, 2024 @05:59PM
(#41342005)
When you call to_owned, it creates a Vec<u8>. This must then be truncated due to the call to into_boxed_slice. The documentation says this could potentially mean a re-allocation depending on the allocator. When this happens the old allocation needs to be dropped too. You could try using a different allocator but before this I would recommend to replace those two calls with Box::from(s.as_bytes()).
[ Parent
| on HN ]
Re:Small Strings in Rust: smolstr vs. smartstring
by skitter on Saturday August 24, 2024 @08:21PM
(#41343144)
The vec already gets allocated with capacity == length
https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#16...