about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-08-24 01:17:52 +0000
committerbors <bors@rust-lang.org>2022-08-24 01:17:52 +0000
commit25ea5a36c6e3a4fa1f739538d9e89eb1cd747564 (patch)
tree1b0a34108e05895e8e5026f5555b4d9b893837a6 /compiler/rustc_parse/src/parser/expr.rs
parent87991d5f5d72d6baca490141cb890211ba2f3843 (diff)
parentddeb936c6d797d47ec8652c885c8a2cceba8386f (diff)
downloadrust-25ea5a36c6e3a4fa1f739538d9e89eb1cd747564.tar.gz
rust-25ea5a36c6e3a4fa1f739538d9e89eb1cd747564.zip
Auto merge of #96869 - sunfishcode:main, r=joshtriplett
Optimize `Wtf8Buf::into_string` for the case where it contains UTF-8.

Add a `is_known_utf8` flag to `Wtf8Buf`, which tracks whether the
string is known to contain UTF-8. This is efficiently computed in many
common situations, such as when a `Wtf8Buf` is constructed from a `String`
or `&str`, or with `Wtf8Buf::from_wide` which is already doing UTF-16
decoding and already checking for surrogates.

This makes `OsString::into_string` O(1) rather than O(N) on Windows in
common cases.

And, it eliminates the need to scan through the string for surrogates in
`Args::next` and `Vars::next`, because the strings are already being
translated with `Wtf8Buf::from_wide`.

Many things on Windows construct `OsString`s with `Wtf8Buf::from_wide`,
such as `DirEntry::file_name` and `fs::read_link`, so with this patch,
users of those functions can subsequently call `.into_string()` without
paying for an extra scan through the string for surrogates.

r? `@ghost`
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
0 files changed, 0 insertions, 0 deletions