Skip to content

Commit e39ea00

Browse files
GnomedDevzonyitoo
authored andcommitted
Avoid reallocating for trimming
1 parent 43eeb8b commit e39ea00

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ test = true
1818
cfg-if = "1.0"
1919
unicase = { version = "2.6", optional = true }
2020
ordered-multimap = "0.7"
21+
trim-in-place = "0.1.7"
2122

2223
[features]
2324
default = []

src/lib.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ use ordered_multimap::{
5858
list_ordered_multimap::{Entry, IntoIter, Iter, IterMut, OccupiedEntry, VacantEntry},
5959
ListOrderedMultimap,
6060
};
61+
use trim_in_place::TrimInPlace;
6162
#[cfg(feature = "case-insensitive")]
6263
use unicase::UniCase;
6364

@@ -1297,9 +1298,9 @@ impl<'a> Parser<'a> {
12971298
self.parse_comment();
12981299
}
12991300
'[' => match self.parse_section() {
1300-
Ok(sec) => {
1301-
let msec = sec[..].trim();
1302-
cursec = Some((*msec).to_string());
1301+
Ok(mut sec) => {
1302+
sec.trim_in_place();
1303+
cursec = Some(sec);
13031304
match result.entry(cursec.clone()) {
13041305
SectionEntry::Vacant(v) => {
13051306
v.insert(Default::default());
@@ -1316,8 +1317,8 @@ impl<'a> Parser<'a> {
13161317
return self.error("missing key");
13171318
}
13181319
match self.parse_val() {
1319-
Ok(val) => {
1320-
let mval = val[..].trim().to_owned();
1320+
Ok(mut mval) => {
1321+
mval.trim_in_place();
13211322
match result.entry(cursec.clone()) {
13221323
SectionEntry::Vacant(v) => {
13231324
// cursec must be None (the General Section)
@@ -1336,8 +1337,8 @@ impl<'a> Parser<'a> {
13361337
}
13371338
}
13381339
_ => match self.parse_key() {
1339-
Ok(key) => {
1340-
let mkey: String = key[..].trim().to_owned();
1340+
Ok(mut mkey) => {
1341+
mkey.trim_in_place();
13411342
curkey = mkey;
13421343
}
13431344
Err(e) => return Err(e),

0 commit comments

Comments
 (0)