Skip to content

Commit b7ee4da

Browse files
committed
perf(toml): Reuse allocations where possible
1 parent a3d68ce commit b7ee4da

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/file/format/toml.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@ pub(crate) fn parse(
88
text: &str,
99
) -> Result<Map<String, Value>, Box<dyn Error + Send + Sync>> {
1010
// Parse a TOML value from the provided text
11-
let table = from_toml_table(uri, &toml::from_str(text)?);
11+
let table = from_toml_table(uri, toml::from_str(text)?);
1212
Ok(table)
1313
}
1414

15-
fn from_toml_table(uri: Option<&String>, table: &toml::Table) -> Map<String, Value> {
15+
fn from_toml_table(uri: Option<&String>, table: toml::Table) -> Map<String, Value> {
1616
let mut m = Map::new();
1717

1818
for (key, value) in table {
19-
m.insert(key.clone(), from_toml_value(uri, value));
19+
m.insert(key, from_toml_value(uri, value));
2020
}
2121

2222
m
2323
}
2424

25-
fn from_toml_value(uri: Option<&String>, value: &toml::Value) -> Value {
26-
match *value {
27-
toml::Value::String(ref value) => Value::new(uri, value.clone()),
25+
fn from_toml_value(uri: Option<&String>, value: toml::Value) -> Value {
26+
match value {
27+
toml::Value::String(value) => Value::new(uri, value),
2828
toml::Value::Float(value) => Value::new(uri, value),
2929
toml::Value::Integer(value) => Value::new(uri, value),
3030
toml::Value::Boolean(value) => Value::new(uri, value),
3131

32-
toml::Value::Table(ref table) => {
32+
toml::Value::Table(table) => {
3333
let m = from_toml_table(uri, table);
3434
Value::new(uri, m)
3535
}
3636

37-
toml::Value::Array(ref array) => {
37+
toml::Value::Array(array) => {
3838
let mut l = Vec::new();
3939

4040
for value in array {
@@ -44,6 +44,6 @@ fn from_toml_value(uri: Option<&String>, value: &toml::Value) -> Value {
4444
Value::new(uri, l)
4545
}
4646

47-
toml::Value::Datetime(ref datetime) => Value::new(uri, datetime.to_string()),
47+
toml::Value::Datetime(datetime) => Value::new(uri, datetime.to_string()),
4848
}
4949
}

0 commit comments

Comments
 (0)