From 5a6f8cac09770d315fe4a3258fa6116e65750f24 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sun, 29 Jan 2023 21:33:34 -0500 Subject: first pass compile time optimization --- src/discord/activity.hpp | 1 - src/discord/channel.cpp | 1 - src/discord/discord.cpp | 2 -- src/discord/guild.cpp | 1 - src/discord/interactions.cpp | 1 - src/discord/json.hpp | 36 ++++++++++++++++++------------------ src/discord/member.cpp | 1 - src/discord/permissions.hpp | 5 +++-- src/discord/snowflake.cpp | 1 - src/discord/store.hpp | 1 - src/discord/user.cpp | 1 - 11 files changed, 21 insertions(+), 30 deletions(-) (limited to 'src/discord') diff --git a/src/discord/activity.hpp b/src/discord/activity.hpp index 4382ac0..5b2c3ce 100644 --- a/src/discord/activity.hpp +++ b/src/discord/activity.hpp @@ -1,7 +1,6 @@ #pragma once #include #include -#include "util.hpp" #include "json.hpp" #include "snowflake.hpp" diff --git a/src/discord/channel.cpp b/src/discord/channel.cpp index 1806201..4b1d909 100644 --- a/src/discord/channel.cpp +++ b/src/discord/channel.cpp @@ -1,4 +1,3 @@ -#include "abaddon.hpp" #include "channel.hpp" void from_json(const nlohmann::json &j, ThreadMetadataData &m) { diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index d7cee4c..c1b32d9 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -1,6 +1,4 @@ -#include "abaddon.hpp" #include "discord.hpp" -#include "util.hpp" #include #include diff --git a/src/discord/guild.cpp b/src/discord/guild.cpp index bb99044..06c4acf 100644 --- a/src/discord/guild.cpp +++ b/src/discord/guild.cpp @@ -1,5 +1,4 @@ #include "guild.hpp" -#include "abaddon.hpp" void from_json(const nlohmann::json &j, GuildData &m) { JS_D("id", m.ID); diff --git a/src/discord/interactions.cpp b/src/discord/interactions.cpp index cc439fc..e23fc86 100644 --- a/src/discord/interactions.cpp +++ b/src/discord/interactions.cpp @@ -1,6 +1,5 @@ #include "interactions.hpp" #include "json.hpp" -#include "abaddon.hpp" void from_json(const nlohmann::json &j, MessageInteractionData &m) { JS_D("id", m.ID); diff --git a/src/discord/json.hpp b/src/discord/json.hpp index 3c6968d..b781e78 100644 --- a/src/discord/json.hpp +++ b/src/discord/json.hpp @@ -1,24 +1,24 @@ #pragma once #include #include -#include "util.hpp" +#include "misc/is_optional.hpp" namespace detail { // more or less because idk what to name this stuff template -inline void json_direct(const ::nlohmann::json &j, const char *key, T &val) { - if constexpr (::util::is_optional::value) +inline void json_direct(const nlohmann::json &j, const char *key, T &val) { + if constexpr (is_optional::value) val = j.at(key).get(); else j.at(key).get_to(val); } template -inline void json_optional(const ::nlohmann::json &j, const char *key, T &val) { - if constexpr (::util::is_optional::value) { +inline void json_optional(const nlohmann::json &j, const char *key, T &val) { + if constexpr (is_optional::value) { if (j.contains(key)) val = j.at(key).get(); else - val = ::std::nullopt; + val = std::nullopt; } else { if (j.contains(key)) j.at(key).get_to(val); @@ -26,13 +26,13 @@ inline void json_optional(const ::nlohmann::json &j, const char *key, T &val) { } template -inline void json_nullable(const ::nlohmann::json &j, const char *key, T &val) { - if constexpr (::util::is_optional::value) { +inline void json_nullable(const nlohmann::json &j, const char *key, T &val) { + if constexpr (is_optional::value) { const auto &at = j.at(key); if (!at.is_null()) val = at.get(); else - val = ::std::nullopt; + val = std::nullopt; } else { const auto &at = j.at(key); if (!at.is_null()) @@ -41,16 +41,16 @@ inline void json_nullable(const ::nlohmann::json &j, const char *key, T &val) { } template -inline void json_optional_nullable(const ::nlohmann::json &j, const char *key, T &val) { - if constexpr (::util::is_optional::value) { +inline void json_optional_nullable(const nlohmann::json &j, const char *key, T &val) { + if constexpr (is_optional::value) { if (j.contains(key)) { const auto &at = j.at(key); if (!at.is_null()) val = at.get(); else - val = ::std::nullopt; + val = std::nullopt; } else { - val = ::std::nullopt; + val = std::nullopt; } } else { if (j.contains(key)) { @@ -62,14 +62,14 @@ inline void json_optional_nullable(const ::nlohmann::json &j, const char *key, T } template -inline void json_update_optional_nullable(const ::nlohmann::json &j, const char *key, T &val) { - if constexpr (::util::is_optional::value) { +inline void json_update_optional_nullable(const nlohmann::json &j, const char *key, T &val) { + if constexpr (is_optional::value) { if (j.contains(key)) { const auto &at = j.at(key); if (!at.is_null()) val = at.get(); else - val = ::std::nullopt; + val = std::nullopt; } } else { if (j.contains(key)) { @@ -83,8 +83,8 @@ inline void json_update_optional_nullable(const ::nlohmann::json &j, const char } template -inline void json_update_optional_nullable_default(const ::nlohmann::json &j, const char *key, T &val, const U &fallback) { - if constexpr (::util::is_optional::value) { +inline void json_update_optional_nullable_default(const nlohmann::json &j, const char *key, T &val, const U &fallback) { + if constexpr (is_optional::value) { if (j.contains(key)) { const auto &at = j.at(key); if (at.is_null()) diff --git a/src/discord/member.cpp b/src/discord/member.cpp index e424491..2a8ae24 100644 --- a/src/discord/member.cpp +++ b/src/discord/member.cpp @@ -1,5 +1,4 @@ #include "member.hpp" -#include "abaddon.hpp" void from_json(const nlohmann::json &j, GuildMember &m) { JS_O("user", m.User); diff --git a/src/discord/permissions.hpp b/src/discord/permissions.hpp index 56ef742..d274dd9 100644 --- a/src/discord/permissions.hpp +++ b/src/discord/permissions.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include "snowflake.hpp" #include "json.hpp" -#include "util.hpp" +#include "misc/bitwise.hpp" +#include "snowflake.hpp" constexpr static uint64_t PERMISSION_MAX_BIT = 36; enum class Permission : uint64_t { @@ -46,6 +46,7 @@ enum class Permission : uint64_t { ALL = 0x1FFFFFFFFFULL, }; + template<> struct Bitwise { static const bool enable = true; diff --git a/src/discord/snowflake.cpp b/src/discord/snowflake.cpp index 856e2f7..15dacae 100644 --- a/src/discord/snowflake.cpp +++ b/src/discord/snowflake.cpp @@ -1,5 +1,4 @@ #include "snowflake.hpp" -#include "util.hpp" #include #include #include diff --git a/src/discord/store.hpp b/src/discord/store.hpp index f1e2f05..8e57e43 100644 --- a/src/discord/store.hpp +++ b/src/discord/store.hpp @@ -1,5 +1,4 @@ #pragma once -#include "util.hpp" #include "objects.hpp" #include #include diff --git a/src/discord/user.cpp b/src/discord/user.cpp index 0ab2af5..2ee7361 100644 --- a/src/discord/user.cpp +++ b/src/discord/user.cpp @@ -1,5 +1,4 @@ #include "user.hpp" -#include "abaddon.hpp" bool UserData::IsABot() const noexcept { return IsBot.has_value() && *IsBot; -- cgit v1.2.3