commands: precalculate capacity and use iterators
This commit is contained in:
@@ -18,10 +18,10 @@ impl Command for ProtocolDisable {
|
||||
}
|
||||
|
||||
// TODO: verify that the features are split by whitespace
|
||||
let mut features = Vec::new();
|
||||
for feature in parts {
|
||||
features.push(feature.to_string());
|
||||
}
|
||||
let features = parts
|
||||
.into_iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
Ok((Request::ProtocolDisable(features), ""))
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ impl Command for ProtocolEnable {
|
||||
}
|
||||
|
||||
// TODO: verify that the features are split by whitespace
|
||||
let mut features = Vec::new();
|
||||
for feature in parts {
|
||||
features.push(feature.to_string());
|
||||
}
|
||||
let features = parts
|
||||
.into_iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
Ok((Request::ProtocolEnable(features), ""))
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ impl Command for TagTypesDisable {
|
||||
}
|
||||
|
||||
// TODO: verify that the tag types are split by whitespace
|
||||
let mut tag_types = Vec::new();
|
||||
for tag_type in parts {
|
||||
tag_types.push(tag_type.to_string());
|
||||
}
|
||||
let tag_types = parts
|
||||
.into_iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
Ok((Request::TagTypesDisable(tag_types), ""))
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ impl Command for TagTypesEnable {
|
||||
}
|
||||
|
||||
// TODO: verify that the tag types are split by whitespace
|
||||
let mut tag_types = Vec::new();
|
||||
for tag_type in parts {
|
||||
tag_types.push(tag_type.to_string());
|
||||
}
|
||||
let tag_types = parts
|
||||
.into_iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
Ok((Request::TagTypesEnable(tag_types), ""))
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ impl Command for TagTypesReset {
|
||||
}
|
||||
|
||||
// TODO: verify that the tag types are split by whitespace
|
||||
let mut tag_types = Vec::new();
|
||||
for tag_type in parts {
|
||||
tag_types.push(tag_type.to_string());
|
||||
}
|
||||
let tag_types = parts
|
||||
.into_iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
Ok((Request::TagTypesReset(tag_types), ""))
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ impl Command for Commands {
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: Vec<_> = parts.into();
|
||||
let mut result = Vec::new();
|
||||
let mut result = Vec::with_capacity(parts.len());
|
||||
for (key, value) in parts.into_iter() {
|
||||
if key != "command" {
|
||||
return Err(ResponseParserError::UnexpectedProperty(key));
|
||||
|
||||
@@ -19,7 +19,7 @@ impl Command for NotCommands {
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: Vec<_> = parts.into();
|
||||
let mut result = Vec::new();
|
||||
let mut result = Vec::with_capacity(parts.len());
|
||||
for (key, value) in parts.into_iter() {
|
||||
if key != "command" {
|
||||
return Err(ResponseParserError::UnexpectedProperty(key));
|
||||
|
||||
@@ -19,7 +19,7 @@ impl Command for UrlHandlers {
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: Vec<_> = parts.into();
|
||||
let mut url_handlers = Vec::new();
|
||||
let mut url_handlers = Vec::with_capacity(parts.len());
|
||||
for (key, value) in parts.into_iter() {
|
||||
if key != "handler" {
|
||||
return Err(ResponseParserError::UnexpectedProperty(key));
|
||||
|
||||
@@ -71,7 +71,7 @@ impl Command for StickerFind {
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: Vec<_> = parts.into();
|
||||
let mut stickers = Vec::new();
|
||||
let mut stickers = Vec::with_capacity(parts.len() / 2);
|
||||
|
||||
for sticker_uri_pair in parts.chunks_exact(2) {
|
||||
// TODO: don't assume that the order of the properties is fixed
|
||||
|
||||
Reference in New Issue
Block a user