Skip to content

Commit f660783

Browse files
Replace regex with find calls
1 parent bc42609 commit f660783

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/librustdoc/html/render/write_shared.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use std::str::FromStr;
2626
use std::{fmt, fs};
2727

2828
use indexmap::IndexMap;
29-
use regex::Regex;
3029
use rustc_ast::join_path_syms;
3130
use rustc_data_structures::flock;
3231
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
@@ -376,12 +375,16 @@ fn hack_get_external_crate_names(
376375
};
377376
// this is only run once so it's fine not to cache it
378377
// !dot_matches_new_line: all crates on same line. greedy: match last bracket
379-
let regex = Regex::new(r"\[.*\]").unwrap();
380-
let Some(content) = regex.find(&content) else {
381-
return Err(Error::new("could not find crates list in crates.js", path));
382-
};
383-
let content: Vec<String> = try_err!(serde_json::from_str(content.as_str()), &path);
384-
Ok(content)
378+
379+
if let Some(start) = content.find('[')
380+
&& let Some(end) = content[start..].find(']')
381+
{
382+
let content: Vec<String> =
383+
try_err!(serde_json::from_str(&content[start..=start + end]), &path);
384+
Ok(content)
385+
} else {
386+
Err(Error::new("could not find crates list in crates.js", path))
387+
}
385388
}
386389

387390
#[derive(Serialize, Deserialize, Clone, Default, Debug)]

0 commit comments

Comments
 (0)