diff options
| author | Zeyla Hellyer <[email protected]> | 2017-10-18 08:34:06 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-10-18 08:34:06 -0700 |
| commit | 9908999a6bae1585bb70b7814f13b49bf99b6c32 (patch) | |
| tree | d789f716400502ae0d124933f5c4d927867e7033 /src/builder/get_messages.rs | |
| parent | Fix some compilation feature targets, fix lints (diff) | |
| download | serenity-9908999a6bae1585bb70b7814f13b49bf99b6c32.tar.xz serenity-9908999a6bae1585bb70b7814f13b49bf99b6c32.zip | |
Slightly improve performance of builders
Builders would keep a `serde_json::Map<String, Value>`, which would
require re-creating owned strings for the same parameter multiple times
in some cases, depending on builder defaults and keying strategies.
This commit uses a `std::collections::HashMap<&'static str, Value>`
internally, and moves over values to a `serde_json::Map<String, Value>`
when it comes time to sending them to the appropriate `http` module
function.
This saves the number of heap-allocated string creations on most
builders, with specific performance increase on `builder::CreateMessage`
and `builder::CreateEmbed` & co.
Diffstat (limited to 'src/builder/get_messages.rs')
| -rw-r--r-- | src/builder/get_messages.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/builder/get_messages.rs b/src/builder/get_messages.rs index 71af9e5..e59584f 100644 --- a/src/builder/get_messages.rs +++ b/src/builder/get_messages.rs @@ -1,5 +1,5 @@ -use std::collections::BTreeMap; use model::MessageId; +use std::collections::HashMap; /// Builds a request for a request to the API to retrieve messages. /// @@ -50,13 +50,13 @@ use model::MessageId; /// /// [`GuildChannel::messages`]: ../model/struct.GuildChannel.html#method.messages #[derive(Clone, Debug, Default)] -pub struct GetMessages(pub BTreeMap<String, u64>); +pub struct GetMessages(pub HashMap<&'static str, u64>); impl GetMessages { /// Indicates to retrieve the messages after a specific message, given by /// its Id. pub fn after<M: Into<MessageId>>(mut self, message_id: M) -> Self { - self.0.insert("after".to_string(), message_id.into().0); + self.0.insert("after", message_id.into().0); self } @@ -64,7 +64,7 @@ impl GetMessages { /// Indicates to retrieve the messages _around_ a specific message in either /// direction (before+after) the given message. pub fn around<M: Into<MessageId>>(mut self, message_id: M) -> Self { - self.0.insert("around".to_string(), message_id.into().0); + self.0.insert("around", message_id.into().0); self } @@ -72,7 +72,7 @@ impl GetMessages { /// Indicates to retrieve the messages before a specific message, given by /// its Id. pub fn before<M: Into<MessageId>>(mut self, message_id: M) -> Self { - self.0.insert("before".to_string(), message_id.into().0); + self.0.insert("before", message_id.into().0); self } @@ -86,7 +86,7 @@ impl GetMessages { /// reduced. pub fn limit(mut self, limit: u64) -> Self { self.0 - .insert("limit".to_string(), if limit > 100 { 100 } else { limit }); + .insert("limit", if limit > 100 { 100 } else { limit }); self } |