Preallocate a few more response parsers
This commit is contained in:
@@ -34,7 +34,10 @@ impl CommandResponse for OutputsResponse {
|
||||
}
|
||||
|
||||
fn parse(parts: ResponseAttributes<'_>) -> Result<Self, ResponseParserError> {
|
||||
let mut outputs = Vec::new();
|
||||
let parts = parts.into_vec()?;
|
||||
|
||||
let result_len = parts.iter().filter(|(k, _)| *k == "outputid").count();
|
||||
let mut outputs = Vec::with_capacity(result_len);
|
||||
|
||||
let mut id: Option<AudioOutputId> = None;
|
||||
let mut name: Option<String> = None;
|
||||
@@ -42,7 +45,7 @@ impl CommandResponse for OutputsResponse {
|
||||
let mut enabled: Option<bool> = None;
|
||||
let mut attributes: HashMap<String, String> = HashMap::new();
|
||||
|
||||
for (k, v) in parts.into_vec()?.into_iter() {
|
||||
for (k, v) in parts.into_iter() {
|
||||
match k {
|
||||
"outputid" => {
|
||||
// Reset and store the previous output if all fields are present
|
||||
|
||||
@@ -38,7 +38,7 @@ impl CommandRequest for ProtocolDisableRequest {
|
||||
return Err(RequestParserError::UnexpectedEOF);
|
||||
}
|
||||
|
||||
let mut features = Vec::new();
|
||||
let mut features = Vec::with_capacity(parts.size_hint().0);
|
||||
for part in parts {
|
||||
let feature = part
|
||||
.parse()
|
||||
|
||||
@@ -38,7 +38,7 @@ impl CommandRequest for ProtocolEnableRequest {
|
||||
return Err(RequestParserError::UnexpectedEOF);
|
||||
}
|
||||
|
||||
let mut features = Vec::new();
|
||||
let mut features = Vec::with_capacity(parts.size_hint().0);
|
||||
for part in parts {
|
||||
let feature = part
|
||||
.parse()
|
||||
|
||||
@@ -68,7 +68,8 @@ impl CommandResponse for StickerNamesTypesResponse {
|
||||
|
||||
fn parse(parts: ResponseAttributes<'_>) -> Result<Self, ResponseParserError> {
|
||||
let parts: Vec<_> = parts.into_vec()?;
|
||||
let mut result = HashMap::new();
|
||||
debug_assert!(parts.len() % 2 == 0);
|
||||
let mut result = HashMap::with_capacity(parts.len() / 2);
|
||||
|
||||
for name_type_pair in parts.chunks_exact(2) {
|
||||
// TODO: don't depend on order, just make sure we have both
|
||||
|
||||
Reference in New Issue
Block a user