Avoid unnecessary allocations.
This commit is contained in:
parent
4194e2c048
commit
b4fea634b0
@ -156,11 +156,13 @@ pub fn format_map_as_json(map: &Map) -> String {
|
|||||||
let mut result = String::from('{');
|
let mut result = String::from('{');
|
||||||
|
|
||||||
for (key, value) in map {
|
for (key, value) in map {
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
if result.len() > 1 {
|
if result.len() > 1 {
|
||||||
result.push(',');
|
result.push(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
result.push_str(&format!("{:?}", key));
|
write!(result, "{:?}", key).unwrap();
|
||||||
result.push(':');
|
result.push(':');
|
||||||
|
|
||||||
if let Some(val) = value.read_lock::<Map>() {
|
if let Some(val) = value.read_lock::<Map>() {
|
||||||
@ -171,7 +173,7 @@ pub fn format_map_as_json(map: &Map) -> String {
|
|||||||
if value.is::<()>() {
|
if value.is::<()>() {
|
||||||
result.push_str("null");
|
result.push_str("null");
|
||||||
} else {
|
} else {
|
||||||
result.push_str(&format!("{:?}", value));
|
write!(result, "{:?}", value).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,12 +195,16 @@ mod print_debug_functions {
|
|||||||
result.push_str("#{");
|
result.push_str("#{");
|
||||||
|
|
||||||
map.iter_mut().enumerate().for_each(|(i, (k, v))| {
|
map.iter_mut().enumerate().for_each(|(i, (k, v))| {
|
||||||
result.push_str(&format!(
|
use std::fmt::Write;
|
||||||
|
|
||||||
|
write!(
|
||||||
|
result,
|
||||||
"{:?}: {}{}",
|
"{:?}: {}{}",
|
||||||
k,
|
k,
|
||||||
&print_with_func(FUNC_TO_DEBUG, &ctx, v),
|
&print_with_func(FUNC_TO_DEBUG, &ctx, v),
|
||||||
if i < len - 1 { ", " } else { "" }
|
if i < len - 1 { ", " } else { "" }
|
||||||
));
|
)
|
||||||
|
.unwrap();
|
||||||
});
|
});
|
||||||
|
|
||||||
result.push('}');
|
result.push('}');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user