aflags: remove unnecessary String conversions

Reduce the number of allocations by removing superfluous calls to
to_string: use a &str where possible, and avoid converting a String to a
String.

Bug: N/A
Test: adb shell aflags list
Change-Id: I373018e9ecb393137d11e039ca2c73c0ca5308d7
This commit is contained in:
Mårten Kongstad 2024-03-07 13:59:49 +01:00
parent d408e96505
commit b47f7bae6d

View file

@ -126,7 +126,7 @@ fn format_flag_row(flag: &Flag, info: &PaddingInfo) -> String {
let full_name = flag.qualified_name();
let p0 = info.longest_flag_col + 1;
let val = flag.value.to_string();
let val = &flag.value;
let p1 = info.longest_val_col + 1;
let value_picked_from = flag.value_picked_from.to_string();
@ -161,7 +161,7 @@ fn list() -> Result<String> {
let flags = DeviceConfigSource::list_flags()?;
let padding_info = PaddingInfo {
longest_flag_col: flags.iter().map(|f| f.qualified_name().len()).max().unwrap_or(0),
longest_val_col: flags.iter().map(|f| f.value.to_string().len()).max().unwrap_or(0),
longest_val_col: flags.iter().map(|f| f.value.len()).max().unwrap_or(0),
longest_value_picked_from_col: flags
.iter()
.map(|f| f.value_picked_from.to_string().len())