Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid reallocating for trimming #124

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1293,9 +1294,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 @@ -1312,8 +1313,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 @@ -1332,8 +1333,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
Loading