Use fold
instead of flat_map
This commit is contained in:
parent
6d9ee6ee26
commit
3945480ce7
3 changed files with 8 additions and 10 deletions
|
@ -3867,7 +3867,6 @@ version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"annotate-snippets 0.10.2",
|
"annotate-snippets 0.10.2",
|
||||||
"derive_setters",
|
"derive_setters",
|
||||||
"either",
|
|
||||||
"rustc_ast",
|
"rustc_ast",
|
||||||
"rustc_ast_pretty",
|
"rustc_ast_pretty",
|
||||||
"rustc_data_structures",
|
"rustc_data_structures",
|
||||||
|
|
|
@ -7,7 +7,6 @@ edition = "2021"
|
||||||
# tidy-alphabetical-start
|
# tidy-alphabetical-start
|
||||||
annotate-snippets = "0.10"
|
annotate-snippets = "0.10"
|
||||||
derive_setters = "0.1.6"
|
derive_setters = "0.1.6"
|
||||||
either = "1.5.0"
|
|
||||||
rustc_ast = { path = "../rustc_ast" }
|
rustc_ast = { path = "../rustc_ast" }
|
||||||
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
|
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
|
||||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||||
|
|
|
@ -16,7 +16,6 @@ use std::iter;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use derive_setters::Setters;
|
use derive_setters::Setters;
|
||||||
use either::Either;
|
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
|
||||||
use rustc_data_structures::sync::{DynSend, IntoDynSyncSend, Lrc};
|
use rustc_data_structures::sync::{DynSend, IntoDynSyncSend, Lrc};
|
||||||
use rustc_error_messages::{FluentArgs, SpanLabel};
|
use rustc_error_messages::{FluentArgs, SpanLabel};
|
||||||
|
@ -2609,16 +2608,17 @@ const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[
|
||||||
('\u{2069}', "<EFBFBD>"),
|
('\u{2069}', "<EFBFBD>"),
|
||||||
];
|
];
|
||||||
|
|
||||||
fn normalize_whitespace(str: &str) -> String {
|
fn normalize_whitespace(s: &str) -> String {
|
||||||
// Scan the input string for a character in the ordered table above. If it's present, replace
|
// Scan the input string for a character in the ordered table above. If it's present, replace
|
||||||
// it with it's alternative string (it can be more than 1 char!). Otherwise, retain the input
|
// it with it's alternative string (it can be more than 1 char!). Otherwise, retain the input
|
||||||
// char. At the end, allocate all chars into a string in one operation.
|
// char. At the end, allocate all chars into a string in one operation.
|
||||||
str.chars()
|
s.chars().fold(String::with_capacity(s.len()), |mut s, c| {
|
||||||
.flat_map(|c| match OUTPUT_REPLACEMENTS.binary_search_by_key(&c, |(k, _)| *k) {
|
match OUTPUT_REPLACEMENTS.binary_search_by_key(&c, |(k, _)| *k) {
|
||||||
Ok(i) => Either::Left(OUTPUT_REPLACEMENTS[i].1.chars()),
|
Ok(i) => s.push_str(OUTPUT_REPLACEMENTS[i].1),
|
||||||
_ => Either::Right([c].into_iter()),
|
_ => s.push(c),
|
||||||
})
|
}
|
||||||
.collect()
|
s
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_col_separator(buffer: &mut StyledBuffer, line: usize, col: usize) {
|
fn draw_col_separator(buffer: &mut StyledBuffer, line: usize, col: usize) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue