Preallocate a few more response parsers
Build and test / check (push) Failing after 58s
Build and test / build (push) Failing after 1m23s
Build and test / test (push) Failing after 1m28s
Build and test / docs (push) Failing after 1m1s

This commit is contained in:
2025-12-08 14:27:42 +09:00
parent f80d36e962
commit 2b3ab7389d
4 changed files with 9 additions and 5 deletions
+5 -2
View File
@@ -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()
+2 -1
View File
@@ -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