Skip to content

Commit

Permalink
perf(config): Get small-string optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Page committed Mar 1, 2021
1 parent b582700 commit 75ba4ac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ derive_setters = "0.1"
itertools = "0.10"
serde_json = "1.0"
encoding = "0.2"
kstring = "1.0"

[dev-dependencies]
assert_fs = "1.0"
Expand Down
24 changes: 14 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@ pub struct FileConfig {
pub check_file: Option<bool>,
pub ignore_hex: Option<bool>,
pub identifier_leading_digits: Option<bool>,
pub identifier_leading_chars: Option<String>,
pub identifier_leading_chars: Option<kstring::KString>,
pub identifier_include_digits: Option<bool>,
pub identifier_include_chars: Option<String>,
pub identifier_include_chars: Option<kstring::KString>,
pub locale: Option<Locale>,
pub extend_identifiers: HashMap<String, String>,
pub extend_words: HashMap<String, String>,
pub extend_identifiers: HashMap<kstring::KString, kstring::KString>,
pub extend_words: HashMap<kstring::KString, kstring::KString>,
}

impl FileConfig {
Expand All @@ -277,9 +277,13 @@ impl FileConfig {
check_file: Some(empty.check_file()),
ignore_hex: Some(empty.ignore_hex()),
identifier_leading_digits: Some(empty.identifier_leading_digits()),
identifier_leading_chars: Some(empty.identifier_leading_chars().to_owned()),
identifier_leading_chars: Some(kstring::KString::from_ref(
empty.identifier_leading_chars(),
)),
identifier_include_digits: Some(empty.identifier_include_digits()),
identifier_include_chars: Some(empty.identifier_include_chars().to_owned()),
identifier_include_chars: Some(kstring::KString::from_ref(
empty.identifier_include_chars(),
)),
locale: Some(empty.locale()),
extend_identifiers: Default::default(),
extend_words: Default::default(),
Expand All @@ -303,26 +307,26 @@ impl FileConfig {
self.identifier_leading_digits = Some(source);
}
if let Some(source) = source.identifier_leading_chars() {
self.identifier_leading_chars = Some(source.to_owned());
self.identifier_leading_chars = Some(kstring::KString::from_ref(source));
}
if let Some(source) = source.identifier_include_digits() {
self.identifier_include_digits = Some(source);
}
if let Some(source) = source.identifier_include_chars() {
self.identifier_include_chars = Some(source.to_owned());
self.identifier_include_chars = Some(kstring::KString::from_ref(source));
}
if let Some(source) = source.locale() {
self.locale = Some(source);
}
self.extend_identifiers.extend(
source
.extend_identifiers()
.map(|(k, v)| (k.to_owned(), v.to_owned())),
.map(|(k, v)| (kstring::KString::from_ref(k), kstring::KString::from_ref(v))),
);
self.extend_words.extend(
source
.extend_words()
.map(|(k, v)| (k.to_owned(), v.to_owned())),
.map(|(k, v)| (kstring::KString::from_ref(k), kstring::KString::from_ref(v))),
);
}

Expand Down

0 comments on commit 75ba4ac

Please sign in to comment.