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 /tests/test_create_embed.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 'tests/test_create_embed.rs')
| -rw-r--r-- | tests/test_create_embed.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/tests/test_create_embed.rs b/tests/test_create_embed.rs index 8cc0de7..01a7d3e 100644 --- a/tests/test_create_embed.rs +++ b/tests/test_create_embed.rs @@ -8,7 +8,7 @@ extern crate serenity; use serde_json::Value; use serenity::model::{Embed, EmbedField, EmbedImage}; use serenity::utils::builder::CreateEmbed; -use serenity::utils::Colour; +use serenity::utils::{self, Colour}; #[test] fn test_from_embed() { @@ -51,7 +51,7 @@ fn test_from_embed() { .title("still a hakase") .url("https://i.imgur.com/XfWpfCV.gif"); - let built = Value::Object(builder.0); + let built = Value::Object(utils::hashmap_to_json_map(builder.0)); let obj = json!({ "color": 0xFF0011, |