diff --git a/src/server/game/Server/Packets/PacketUtilities.h b/src/server/game/Server/Packets/PacketUtilities.h index 5744140d..b5e87f98 100644 --- a/src/server/game/Server/Packets/PacketUtilities.h +++ b/src/server/game/Server/Packets/PacketUtilities.h @@ -65,7 +65,7 @@ namespace WorldPackets namespace Strings { - struct RawBytes { static void Validate(std::string_view /*value*/) { } }; + struct RawBytes { static void Validate(std::string_view /*value*/) {} }; struct ByteSize { static void Validate(std::string_view value, std::size_t maxSize); }; struct Utf8 { static void Validate(std::string_view value); }; struct Hyperlinks { static void Validate(std::string_view value); }; @@ -152,6 +152,7 @@ namespace WorldPackets { using allocator_type = short_alloc::short_alloc; using resource_type = typename allocator_type::arena_type; + using reserve_max_capacity = std::true_type; }; // don't store elements inline when size is large @@ -160,6 +161,7 @@ namespace WorldPackets { using allocator_type = std::allocator; using resource_type = std::allocator; + using reserve_max_capacity = std::false_type; }; /** @@ -169,9 +171,10 @@ namespace WorldPackets class Array { public: - using allocator_traits = ArrayAllocatorTraits 0x1000)>; + using allocator_traits = ArrayAllocatorTraits 0x1000)>; using allocator_type = typename allocator_traits::allocator_type; using allocator_resource_type = typename allocator_traits::resource_type; + using reserve_max_capacity = typename allocator_traits::reserve_max_capacity; using storage_type = std::vector; @@ -186,10 +189,17 @@ namespace WorldPackets using iterator = typename storage_type::iterator; using const_iterator = typename storage_type::const_iterator; - Array() : _storage(_allocatorResource) { } + Array() : _storage(_allocatorResource) + { + if constexpr (reserve_max_capacity()) + _storage.reserve(max_capacity()); + } Array(Array const& other) : Array() { + if constexpr (reserve_max_capacity()) + _storage.reserve(max_capacity()); + for (T const& element : other) _storage.push_back(element); } @@ -278,8 +288,8 @@ namespace WorldPackets { public: Timestamp() = default; - Timestamp(time_t value) : _value(value) { } - Timestamp(SystemTimePoint const& systemTime) : _value(std::chrono::system_clock::to_time_t(systemTime)) { } + Timestamp(time_t value) : _value(value) {} + Timestamp(SystemTimePoint const& systemTime) : _value(std::chrono::system_clock::to_time_t(systemTime)) {} Timestamp& operator=(time_t value) { @@ -324,7 +334,7 @@ namespace WorldPackets { public: Duration() = default; - Duration(ChronoDuration value) : _value(value) { } + Duration(ChronoDuration value) : _value(value) {} Duration& operator=(ChronoDuration value) {