Skip to content

Commit

Permalink
chore: Reduce code-gen memory usage
Browse files Browse the repository at this point in the history
More `const fn` removals to reduce compilation memory use
  • Loading branch information
epage committed Jun 7, 2021
1 parent a861cbf commit 3a4d039
Show file tree
Hide file tree
Showing 13 changed files with 66,707 additions and 81,209 deletions.
9 changes: 0 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion crates/codespell-dict/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ publish = false
azure-devops = { project = "crate-ci", pipeline = "typos" }
codecov = { repository = "crate-ci/typos" }

[package.metadata.release]
disable-release = true

[dependencies]
phf = { version = "0.8", features = ["unicase"] }
unicase = "2.5"
log = "0.4"
5 changes: 3 additions & 2 deletions crates/codespell-dict/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ publish = false
azure-devops = { project = "crate-ci", pipeline = "typos" }
codecov = { repository = "crate-ci/typos" }

[package.metadata.release]
disable-release = true

[dependencies]
phf = { version = "0.8", features = ["unicase"] }
phf_codegen = "0.8"
unicase = "2.5"
itertools = "0.10"
codegenrs = "1.0"
Expand Down
16 changes: 5 additions & 11 deletions crates/codespell-dict/codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,18 @@ fn generate<W: std::io::Write>(file: &mut W) {
.unwrap();
writeln!(file, "#![allow(clippy::unreadable_literal)]",).unwrap();
writeln!(file).unwrap();
writeln!(file, "use unicase::UniCase;").unwrap();

let dict = parse_dict(DICT);

writeln!(
file,
"pub static WORD_DICTIONARY: phf::Map<unicase::UniCase<&'static str>, &[&'static str]> = ",
)
.unwrap();
let mut builder = phf_codegen::Map::new();
writeln!(file, "pub static WORD_DICTIONARY: &[(&str, &[&str])] = &[").unwrap();
for (typo, corrections) in dict {
let value = itertools::join(corrections.iter().map(|s| format!("{:?}", s)), ", ");
let value = format!("&[{}]", value);
builder.entry(unicase::UniCase::new(typo), &value);

let key = format!("{:?}", typo);
writeln!(file, " ({}, {}),", key, &value).unwrap();
}
let codegenned = builder.build();
writeln!(file, "{}", codegenned).unwrap();
writeln!(file, ";").unwrap();
writeln!(file, "];").unwrap();
}

#[derive(Debug, StructOpt)]
Expand Down

0 comments on commit 3a4d039

Please sign in to comment.