Avoid unnecessary allocations.

This commit is contained in:
Stephen Chung
2022-05-07 16:29:20 +08:00
parent 4194e2c048
commit b4fea634b0
2 changed files with 10 additions and 4 deletions

View File

@@ -156,11 +156,13 @@ pub fn format_map_as_json(map: &Map) -> String {
let mut result = String::from('{');
for (key, value) in map {
use std::fmt::Write;
if result.len() > 1 {
result.push(',');
}
result.push_str(&format!("{:?}", key));
write!(result, "{:?}", key).unwrap();
result.push(':');
if let Some(val) = value.read_lock::<Map>() {
@@ -171,7 +173,7 @@ pub fn format_map_as_json(map: &Map) -> String {
if value.is::<()>() {
result.push_str("null");
} else {
result.push_str(&format!("{:?}", value));
write!(result, "{:?}", value).unwrap();
}
}