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/WorldStorage/MapSerializer.cpp | 53 +++++--------------------------------- 1 file changed, 7 insertions(+), 46 deletions(-) (limited to 'src/WorldStorage/MapSerializer.cpp') diff --git a/src/WorldStorage/MapSerializer.cpp b/src/WorldStorage/MapSerializer.cpp index d030b5a32..40d428dab 100644 --- a/src/WorldStorage/MapSerializer.cpp +++ b/src/WorldStorage/MapSerializer.cpp @@ -4,8 +4,7 @@ #include "Globals.h" #include "MapSerializer.h" -#include "../StringCompression.h" -#include "zlib/zlib.h" +#include "OSSupport/GZipFile.h" #include "FastNBT.h" #include "../Map.h" @@ -32,22 +31,9 @@ cMapSerializer::cMapSerializer(const AString & a_WorldName, cMap * a_Map): bool cMapSerializer::Load(void) { - AString Data = cFile::ReadWholeFile(m_Path); - if (Data.empty()) - { - return false; - } + const auto Data = GZipFile::ReadRestOfFile(m_Path); + const cParsedNBT NBT(Data.GetView()); - AString Uncompressed; - int res = UncompressStringGZIP(Data.data(), Data.size(), Uncompressed); - - if (res != Z_OK) - { - return false; - } - - // Parse the NBT data: - cParsedNBT NBT(Uncompressed.data(), Uncompressed.size()); if (!NBT.IsValid()) { // NBT Parsing failed @@ -64,32 +50,15 @@ bool cMapSerializer::Load(void) bool cMapSerializer::Save(void) { cFastNBTWriter Writer; - SaveMapToNBT(Writer); - Writer.Finish(); #ifdef _DEBUG - cParsedNBT TestParse(Writer.GetResult().data(), Writer.GetResult().size()); + cParsedNBT TestParse(Writer.GetResult()); ASSERT(TestParse.IsValid()); #endif // _DEBUG - cFile File; - if (!File.Open(m_Path, cFile::fmWrite)) - { - return false; - } - - AString Compressed; - int res = CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed); - - if (res != Z_OK) - { - return false; - } - - File.Write(Compressed.data(), Compressed.size()); - File.Close(); + GZipFile::Write(m_Path, Writer.GetResult()); return true; } @@ -225,7 +194,7 @@ bool cIDCountSerializer::Load(void) // NOTE: idcounts.dat is not compressed (raw format) // Parse the NBT data: - cParsedNBT NBT(Data.data(), Data.size()); + cParsedNBT NBT({ reinterpret_cast(Data.data()), Data.size() }); if (!NBT.IsValid()) { // NBT Parsing failed @@ -261,7 +230,7 @@ bool cIDCountSerializer::Save(void) Writer.Finish(); #ifdef _DEBUG - cParsedNBT TestParse(Writer.GetResult().data(), Writer.GetResult().size()); + cParsedNBT TestParse(Writer.GetResult()); ASSERT(TestParse.IsValid()); #endif // _DEBUG @@ -278,11 +247,3 @@ bool cIDCountSerializer::Save(void) return true; } - - - - - - - - -- cgit v1.2.3