Rollup merge of #55530 - ljedrz:speed_up_String_from_utf16, r=SimonSapin
Rollup merge of #55530 - ljedrz:speed_up_String_from_utf16, r=SimonSapin

Speed up String::from_utf16

Collecting into a `Result` is idiomatic, but not necessarily fast due to rustc not being able to preallocate for the resulting collection. This is fine in case of an error, but IMO we should optimize for the common case, i.e. a successful conversion.

This changes the behavior of `String::from_utf16` from collecting into a `Result` to pushing to a preallocated `String` in a loop.

According to [my simple benchmark](https://gist.github.com/ljedrz/953a3fb74058806519bd4d640d6f65ae) this change makes `String::from_utf16` around **twice** as fast.

aidancully/rust,graydon/rust,graydon/rust,GBGamer/rust,graydon/rust,aidancully/rust,GBGamer/rust,GBGamer/rust,GBGamer/rust,GBGamer/rust,aidancully/rust,graydon/rust,GBGamer/rust,aidancully/rust,graydon/rust,graydon/rust,aidancully/rust,GBGamer/rust,GBGamer/rust,aidancully/rust