Skip to content

Commit

Permalink
Avoid reallocating for trimming
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev authored and zonyitoo committed Mar 11, 2024
1 parent 43eeb8b commit e39ea00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ test = true
cfg-if = "1.0"
unicase = { version = "2.6", optional = true }
ordered-multimap = "0.7"
trim-in-place = "0.1.7"

[features]
default = []
Expand Down
15 changes: 8 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use ordered_multimap::{
list_ordered_multimap::{Entry, IntoIter, Iter, IterMut, OccupiedEntry, VacantEntry},
ListOrderedMultimap,
};
use trim_in_place::TrimInPlace;
#[cfg(feature = "case-insensitive")]
use unicase::UniCase;

Expand Down Expand Up @@ -1297,9 +1298,9 @@ impl<'a> Parser<'a> {
self.parse_comment();
}
'[' => match self.parse_section() {
Ok(sec) => {
let msec = sec[..].trim();
cursec = Some((*msec).to_string());
Ok(mut sec) => {
sec.trim_in_place();
cursec = Some(sec);
match result.entry(cursec.clone()) {
SectionEntry::Vacant(v) => {
v.insert(Default::default());
Expand All @@ -1316,8 +1317,8 @@ impl<'a> Parser<'a> {
return self.error("missing key");
}
match self.parse_val() {
Ok(val) => {
let mval = val[..].trim().to_owned();
Ok(mut mval) => {
mval.trim_in_place();
match result.entry(cursec.clone()) {
SectionEntry::Vacant(v) => {
// cursec must be None (the General Section)
Expand All @@ -1336,8 +1337,8 @@ impl<'a> Parser<'a> {
}
}
_ => match self.parse_key() {
Ok(key) => {
let mkey: String = key[..].trim().to_owned();
Ok(mut mkey) => {
mkey.trim_in_place();
curkey = mkey;
}
Err(e) => return Err(e),
Expand Down

0 comments on commit e39ea00

Please sign in to comment.