-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1198 from epage/generic
perf(dict)!: Switch to PHF Map
- Loading branch information
Showing
20 changed files
with
909,326 additions
and
705,237 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
168,511 changes: 84,256 additions & 84,255 deletions
168,511
crates/codespell-dict/src/dict_codegen.rs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#[cfg(feature = "codegen")] | ||
pub struct MatchGen<'g> { | ||
pub(crate) gen: crate::DictGen<'g>, | ||
} | ||
|
||
#[cfg(feature = "codegen")] | ||
impl MatchGen<'_> { | ||
pub fn write<W: std::io::Write, V: std::fmt::Display>( | ||
&self, | ||
file: &mut W, | ||
data: impl Iterator<Item = (impl AsRef<str>, V)>, | ||
) -> Result<(), std::io::Error> { | ||
let mut data: Vec<_> = data.collect(); | ||
data.sort_unstable_by_key(|v| unicase::UniCase::new(v.0.as_ref().to_owned())); | ||
|
||
let name = self.gen.name; | ||
let value_type = self.gen.value_type; | ||
|
||
writeln!(file, "pub struct {name};")?; | ||
writeln!(file, "impl {name} {{")?; | ||
writeln!( | ||
file, | ||
" pub fn find(&self, word: &&str) -> Option<&'static {value_type}> {{" | ||
)?; | ||
writeln!(file, " match *word {{")?; | ||
for (key, value) in data.iter() { | ||
let key = key.as_ref(); | ||
writeln!(file, " {key:?} => Some(&{value}.as_slice()),")?; | ||
} | ||
writeln!(file, " _ => None,")?; | ||
writeln!(file, " }}")?; | ||
writeln!(file, " }}")?; | ||
writeln!(file, "}}")?; | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.