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/model/channel/guild_channel.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/model/channel/guild_channel.rs')
| -rw-r--r-- | src/model/channel/guild_channel.rs | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs index cc74b9d..90bb926 100644 --- a/src/model/channel/guild_channel.rs +++ b/src/model/channel/guild_channel.rs @@ -116,7 +116,9 @@ impl GuildChannel { } } - http::create_invite(self.id.0, &f(CreateInvite::default()).0) + let map = serenity_utils::hashmap_to_json_map(f(CreateInvite::default()).0); + + http::create_invite(self.id.0, &map) } /// Creates a [permission overwrite][`PermissionOverwrite`] for either a @@ -312,18 +314,12 @@ impl GuildChannel { } } - let mut map = Map::new(); - map.insert("name".to_string(), Value::String(self.name.clone())); - map.insert( - "position".to_string(), - Value::Number(Number::from(self.position)), - ); - map.insert( - "type".to_string(), - Value::String(self.kind.name().to_string()), - ); - - let edited = f(EditChannel(map)).0; + let mut map = HashMap::new(); + map.insert("name", Value::String(self.name.clone())); + map.insert("position", Value::Number(Number::from(self.position))); + map.insert("type", Value::String(self.kind.name().to_string())); + + let edited = serenity_utils::hashmap_to_json_map(f(EditChannel(map)).0); match http::edit_channel(self.id.0, &edited) { Ok(channel) => { |