Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch MapBlock compression to zstd #10788

Merged
merged 20 commits into from
Sep 1, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Determine metadata length without an extra ostringstream
  • Loading branch information
lhofhansl committed Aug 29, 2021
commit 3c62a3f1d7670f82303c9dae8c0116df500bbae3
16 changes: 10 additions & 6 deletions src/mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,13 @@ void MapBlock::serialize(std::ostream &os_compressed, u8 version, bool disk, int
/*
Node metadata
*/
u32 metadata_offset = 0;
u32 metadata_length = 0;
if (version >= 29) {
std::ostringstream metadata(std::ios_base::binary);
m_node_metadata.serialize(metadata, version, disk);
std::string metadata_str = metadata.str();
writeU32(os, metadata_str.size());
os.write(metadata_str.c_str(), metadata_str.size());
metadata_offset = os.tellp();
writeU32(os, 0); // placeholder for length
m_node_metadata.serialize(os, version, disk);
metadata_length = (u32)os.tellp() - metadata_offset - sizeof(u32);
} else {
// use os_raw from above to avoid allocating another stream object
m_node_metadata.serialize(os_raw, version, disk);
Expand Down Expand Up @@ -454,8 +455,11 @@ void MapBlock::serialize(std::ostream &os_compressed, u8 version, bool disk, int
}

if(version >= 29) {
// write the metadata length
std::string output = os_raw.str();
writeU32(reinterpret_cast<u8*>(&output[metadata_offset]), metadata_length);
// now compress the whole thing
compress(os_raw.str(), os_compressed, version, compression_level);
compress(output, os_compressed, version, compression_level);
}
}

Expand Down