Skip to content

Commit

Permalink
Avoid allocating strings in Display implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
qwandor committed Jul 26, 2024
1 parent f9cd36a commit f7be927
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/device/sound.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Driver for VirtIO Sound devices.

use alloc::vec;
use alloc::{boxed::Box, collections::BTreeMap, format, vec::Vec};
use alloc::{boxed::Box, collections::BTreeMap, vec::Vec};
use bitflags::bitflags;
use core::{
fmt::{self, Debug, Display, Formatter},
Expand Down Expand Up @@ -1655,16 +1655,19 @@ impl Display for VirtIOSndChmapInfo {
} else {
"OUTPUT"
};
let mut positions = vec![];
for i in 0..self.channels as usize {
let position = format!("{:?}", ChannelPosition::from(self.positions[i]));
positions.push(position);
}
write!(
f,
"direction: {}, channels: {}, postions: {:?}",
direction, self.channels, positions
)
"direction: {}, channels: {}, postions: [",
direction, self.channels
)?;
for i in 0..usize::from(self.channels) {
if i != 0 {
write!(f, ", ")?;
}
write!(f, "{:?}", ChannelPosition::from(self.positions[i]))?;
}
write!(f, "]")?;
Ok(())
}
}

Expand Down

0 comments on commit f7be927

Please sign in to comment.