Skip to content

Commit 09235ca

Browse files
Replace regex with find calls
1 parent b4da593 commit 09235ca

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/librustdoc/html/render/write_shared.rs

Lines changed: 8 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,14 @@ 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+
if let Some((_, content)) = content.split_once('[')
379+
&& let Some((content, _)) = content.split_once(']')
380+
{
381+
let content: Vec<String> = try_err!(serde_json::from_str(content), &path);
382+
Ok(content)
383+
} else {
384+
Err(Error::new("could not find crates list in crates.js", path))
385+
}
385386
}
386387

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

0 commit comments

Comments
 (0)