perf(parser): Allow people to bypass unicode cost

This commit is contained in:
Ed Page committed 2021-04-29 21:07:59 -05:00
1 parent 09d2124d0f
commit 517da7ecd2
5 files changed
+158 -30

No files matched your search

+10
View File
@@ -230,6 +230,8 @@ impl EngineConfig {
#[serde(deny_unknown_fields, default)]
#[serde(rename_all = "kebab-case")]
pub struct TokenizerConfig {
/// Allow unicode characters in identifiers (and not just ASCII)
pub unicode: Option<bool>,
/// Do not check identifiers that appear to be hexadecimal values.
pub ignore_hex: Option<bool>,
/// Allow identifiers to start with digits, in addition to letters.
@@ -240,12 +242,16 @@ impl TokenizerConfig {
pub fn from_defaults() -> Self {
let empty = Self::default();
Self {
unicode: Some(empty.unicode()),
ignore_hex: Some(empty.ignore_hex()),
identifier_leading_digits: Some(empty.identifier_leading_digits()),
}
}
pub fn update(&mut self, source: &TokenizerConfig) {
if let Some(source) = source.unicode {
self.unicode = Some(source);
}
if let Some(source) = source.ignore_hex {
self.ignore_hex = Some(source);
}
@@ -254,6 +260,10 @@ impl TokenizerConfig {
}
}
pub fn unicode(&self) -> bool {
self.unicode.unwrap_or(true)
}
pub fn ignore_hex(&self) -> bool {
self.ignore_hex.unwrap_or(true)
}
+1
View File
@@ -217,6 +217,7 @@ impl<'s> ConfigEngine<'s> {
let dict_config = dict.unwrap_or_else(crate::config::DictConfig::from_defaults);
let tokenizer = typos::tokens::TokenizerBuilder::new()
.unicode(tokenizer_config.unicode())
.ignore_hex(tokenizer_config.ignore_hex())
.leading_digits(tokenizer_config.identifier_leading_digits())
.build();