mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Use escape_default() for strings in LitKind::token().
This avoids converting every char to \u{...} form, which bloats the resulting strings unnecessarily. It also provides consistency with the existing escape_default() calls in LitKind::token() used for raw string literals, char literals, and raw byte char literals. There are two benefits from this change. - Compilation is faster. Most of the rustc-perf benchmarks see a non-trivial speedup, particularly for incremental rebuilds, with the best speedup over 13%, and multiple others over 10%. - Generated rlibs are smaller. An extreme example is libfutures.rlib, which shrinks from 2073306 bytes to 1765927 bytes, a 15% reduction.
This commit is contained in:
parent
f76f6fbdea
commit
d5d389e4f1
@ -1228,10 +1228,7 @@ impl LitKind {
|
||||
|
||||
match *self {
|
||||
LitKind::Str(string, ast::StrStyle::Cooked) => {
|
||||
let mut escaped = String::new();
|
||||
for ch in string.as_str().chars() {
|
||||
escaped.extend(ch.escape_unicode());
|
||||
}
|
||||
let escaped = string.as_str().escape_default();
|
||||
Token::Literal(token::Lit::Str_(Symbol::intern(&escaped)), None)
|
||||
}
|
||||
LitKind::Str(string, ast::StrStyle::Raw(n)) => {
|
||||
|
@ -25,6 +25,7 @@
|
||||
#![feature(non_exhaustive)]
|
||||
#![feature(const_atomic_usize_new)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(str_escape)]
|
||||
|
||||
#![recursion_limit="256"]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user