From eeb63b8901a9c049f1bb594abb9ce9b4a9c47620 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 11 Jan 2021 16:39:43 +0000 Subject: zlib -> libdeflate (#5085) + Use libdeflate + Use std::byte * Fix passing temporary to string_view + Emulate make_unique_for_overwrite --- src/StringUtils.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/StringUtils.cpp') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index e6fbcc6fe..c55456e24 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -972,10 +972,12 @@ AString Base64Encode(const AString & a_Input) -short GetBEShort(const char * a_Mem) +short GetBEShort(const std::byte * const a_Mem) { - const Byte * Bytes = reinterpret_cast(a_Mem); - return static_cast((Bytes[0] << 8) | Bytes[1]); + return static_cast( + (static_cast(a_Mem[0]) << 8) | + static_cast(a_Mem[1]) + ); } @@ -992,22 +994,26 @@ unsigned short GetBEUShort(const char * a_Mem) -int GetBEInt(const char * a_Mem) +int GetBEInt(const std::byte * const a_Mem) { - const Byte * Bytes = reinterpret_cast(a_Mem); - return (Bytes[0] << 24) | (Bytes[1] << 16) | (Bytes[2] << 8) | Bytes[3]; + return + (static_cast(a_Mem[0]) << 24) | + (static_cast(a_Mem[1]) << 16) | + (static_cast(a_Mem[2]) << 8) | + static_cast(a_Mem[3]) + ; } -void SetBEInt(char * a_Mem, Int32 a_Value) +void SetBEInt(std::byte * a_Mem, Int32 a_Value) { - a_Mem[0] = a_Value >> 24; - a_Mem[1] = static_cast((a_Value >> 16) & 0xff); - a_Mem[2] = static_cast((a_Value >> 8) & 0xff); - a_Mem[3] = static_cast(a_Value & 0xff); + a_Mem[0] = std::byte(a_Value >> 24); + a_Mem[1] = std::byte((a_Value >> 16) & 0xff); + a_Mem[2] = std::byte((a_Value >> 8) & 0xff); + a_Mem[3] = std::byte(a_Value & 0xff); } -- cgit v1.2.3