mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-14 15:47:12 +00:00
Optimize crates index generation (reduce 0.4% file size)
This commit is contained in:
parent
6f940d32a4
commit
1e6e85a3eb
4 changed files with 9 additions and 5 deletions
File diff suppressed because one or more lines are too long
|
@ -17,7 +17,10 @@ struct FrequencyWord {
|
|||
impl FrequencyWord {
|
||||
#[inline]
|
||||
fn score(&self) -> usize {
|
||||
self.word.len() * self.frequency
|
||||
// Due to the prefix + suffix occupying two letters,
|
||||
// we should minus the length to calculate the score.
|
||||
// This will lead to a 0.4% reduction in file size.
|
||||
(self.word.len() - 2) * self.frequency
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,9 +69,9 @@ impl Minifier {
|
|||
|
||||
Minifier {
|
||||
mapping: words
|
||||
.iter()
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(index, fw)| (fw.word.clone(), keys.get(index).unwrap().to_owned()))
|
||||
.map(|(index, fw)| (fw.word, keys.get(index).unwrap().to_owned()))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@ fn read_csv<D: DeserializeOwned>(file: impl Read) -> crate::Result<Vec<D>> {
|
|||
|
||||
fn generate_javascript_crates_index(crates: Vec<Crate>, minifier: &Minifier) -> String {
|
||||
let mut contents = String::from("var N=null;");
|
||||
// <name, [optional description, version]>
|
||||
let crates_map: HashMap<String, (Option<String>, Version)> = crates
|
||||
.into_par_iter()
|
||||
.map(|item| {
|
||||
|
|
|
@ -75,7 +75,7 @@ impl LintsTask {
|
|||
.as_ref()
|
||||
.and_then(|d| d.trim().strip_prefix("### What it does"))
|
||||
{
|
||||
let mut desc = docs.replace('`', "").replace('#', "");
|
||||
let mut desc = docs.replace(['`', '#'], "");
|
||||
desc.truncate(100);
|
||||
Some((lint.id.clone(), [lint.level.to_string(), desc]))
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue