diff --git a/Source/dvlnet/base.h b/Source/dvlnet/base.h index a33f5972a..afd4b371d 100644 --- a/Source/dvlnet/base.h +++ b/Source/dvlnet/base.h @@ -3,10 +3,11 @@ #include #include #include -#include #include #include +#include + #include "dvlnet/abstract_net.h" #include "dvlnet/packet.h" #include "multi.h" @@ -41,7 +42,7 @@ public: ~base() override = default; protected: - std::map registered_handlers; + ankerl::unordered_dense::map registered_handlers; buffer_t game_init_info; struct message_t { diff --git a/Source/dvlnet/base_protocol.h b/Source/dvlnet/base_protocol.h index 274c326d9..4634c91c8 100644 --- a/Source/dvlnet/base_protocol.h +++ b/Source/dvlnet/base_protocol.h @@ -1,13 +1,15 @@ #pragma once -#include #include #include #include +#include + #include "dvlnet/base.h" #include "dvlnet/packet.h" #include "player.h" +#include "utils/algorithm/container.hpp" #include "utils/log.hpp" namespace devilution::net { @@ -50,7 +52,7 @@ private: std::vector playerNames; endpoint_t peer; }; - std::map game_list; + ankerl::unordered_dense::map game_list; std::array peers; bool isGameHost_; @@ -535,6 +537,7 @@ std::vector base_protocol

::get_gamelist() const auto &[gameData, players, _] = gameInfo; ret.push_back(GameInfo { name, gameData, players }); } + c_sort(ret, [](const GameInfo &a, const GameInfo &b) { return a.name < b.name; }); return ret; } diff --git a/Source/dvlnet/cdwrap.h b/Source/dvlnet/cdwrap.h index 55ba3523f..1c67e35b8 100644 --- a/Source/dvlnet/cdwrap.h +++ b/Source/dvlnet/cdwrap.h @@ -2,12 +2,12 @@ #include #include -#include #include #include #include #include +#include #include #include "dvlnet/abstract_net.h" @@ -18,7 +18,7 @@ namespace devilution::net { class cdwrap : public abstract_net { private: std::unique_ptr dvlnet_wrap; - std::map registered_handlers; + ankerl::unordered_dense::map registered_handlers; buffer_t game_init_info; std::optional game_pw; tl::function_ref()> make_net_fn_; diff --git a/Source/dvlnet/protocol_zt.cpp b/Source/dvlnet/protocol_zt.cpp index 134614bcc..580d5f31c 100644 --- a/Source/dvlnet/protocol_zt.cpp +++ b/Source/dvlnet/protocol_zt.cpp @@ -277,14 +277,15 @@ bool protocol_zt::get_disconnected(endpoint &peer) void protocol_zt::disconnect(const endpoint &peer) { - if (peer_list.count(peer) != 0) { - if (peer_list[peer].fd != -1) { - if (lwip_close(peer_list[peer].fd) < 0) { + const auto it = peer_list.find(peer); + if (it != peer_list.end()) { + if (it->second.fd != -1) { + if (lwip_close(it->second.fd) < 0) { Log("lwip_close: {}", strerror(errno)); SDL_SetError("lwip_close: %s", strerror(errno)); } } - peer_list.erase(peer); + peer_list.erase(it); } } @@ -328,7 +329,8 @@ uint64_t protocol_zt::current_ms() bool protocol_zt::is_peer_connected(endpoint &peer) { - return peer_list.count(peer) != 0 && peer_list[peer].fd != -1; + const auto it = peer_list.find(peer); + return it != peer_list.end() && it->second.fd != -1; } bool protocol_zt::is_peer_relayed(const endpoint &peer) const diff --git a/Source/dvlnet/protocol_zt.h b/Source/dvlnet/protocol_zt.h index f625acfff..d6830f567 100644 --- a/Source/dvlnet/protocol_zt.h +++ b/Source/dvlnet/protocol_zt.h @@ -6,10 +6,10 @@ #include #include #include -#include -#include #include +#include + #include "dvlnet/frame_queue.h" #include "dvlnet/packet.h" @@ -63,6 +63,15 @@ public: void from_string(const std::string &str); }; + struct EndpointHash { + using is_avalanching = void; + + [[nodiscard]] uint64_t operator()(const endpoint &e) const noexcept + { + return ankerl::unordered_dense::hash {}( + std::string_view { reinterpret_cast(e.addr.data()), e.addr.size() }); + } + }; protocol_zt(); ~protocol_zt(); @@ -90,7 +99,7 @@ private: std::deque> oob_recv_queue; std::deque disconnect_queue; - std::map peer_list; + ankerl::unordered_dense::map peer_list; int fd_tcp = -1; int fd_udp = -1; diff --git a/Source/qol/stash.h b/Source/qol/stash.h index 241a570d9..5172c01aa 100644 --- a/Source/qol/stash.h +++ b/Source/qol/stash.h @@ -6,9 +6,10 @@ #pragma once #include -#include #include +#include + #include "engine/point.hpp" #include "items.h" @@ -21,7 +22,7 @@ public: static constexpr StashCell EmptyCell = -1; void RemoveStashItem(StashCell iv); - std::map stashGrids; + ankerl::unordered_dense::map stashGrids; std::vector stashList; int gold; bool dirty = false; diff --git a/Source/utils/language.cpp b/Source/utils/language.cpp index b9bbc8479..e09dacd6b 100644 --- a/Source/utils/language.cpp +++ b/Source/utils/language.cpp @@ -40,9 +40,9 @@ using TranslationRef = uint32_t; struct StringHash { using is_avalanching = void; - size_t operator()(const char *str) const noexcept + [[nodiscard]] uint64_t operator()(const char *str) const noexcept { - return ankerl::unordered_dense::detail::wyhash::hash(str, std::string_view { str }.size()); + return ankerl::unordered_dense::hash {}(str); } };