mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Use unique_ptr and std::copy
This commit is contained in:
parent
0da467c374
commit
23c985ee60
1 changed files with 5 additions and 5 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "mapblock.h"
|
#include "mapblock.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "light.h"
|
#include "light.h"
|
||||||
|
@ -310,7 +311,7 @@ void MapBlock::expireIsAirCache()
|
||||||
// Renumbers the content IDs (starting at 0 and incrementing)
|
// Renumbers the content IDs (starting at 0 and incrementing)
|
||||||
// Note that there's no technical reason why we *have to* renumber the IDs,
|
// Note that there's no technical reason why we *have to* renumber the IDs,
|
||||||
// but we do it anyway as it also helps compressability.
|
// but we do it anyway as it also helps compressability.
|
||||||
static void getBlockNodeIdMapping(NameIdMapping *nimap, MapNode *nodes,
|
static void getBlockNodeIdMapping(NameIdMapping *nimap, const std::unique_ptr<MapNode[]> &nodes,
|
||||||
const NodeDefManager *nodedef, u32 nodecount)
|
const NodeDefManager *nodedef, u32 nodecount)
|
||||||
{
|
{
|
||||||
IdIdMapping &mapping = IdIdMapping::giveClearedThreadLocalInstance();
|
IdIdMapping &mapping = IdIdMapping::giveClearedThreadLocalInstance();
|
||||||
|
@ -430,13 +431,12 @@ void MapBlock::serialize(std::ostream &os_compressed, u8 version, bool disk, int
|
||||||
if(disk)
|
if(disk)
|
||||||
{
|
{
|
||||||
const size_t size = m_is_mono_block ? 1 : nodecount;
|
const size_t size = m_is_mono_block ? 1 : nodecount;
|
||||||
MapNode *tmp_nodes = new MapNode[size];
|
auto tmp_nodes = std::make_unique<MapNode[]>(size);
|
||||||
memcpy(tmp_nodes, data, size * sizeof(MapNode));
|
std::copy(data, data+size, tmp_nodes.get());
|
||||||
getBlockNodeIdMapping(&nimap, tmp_nodes, m_gamedef->ndef(), size);
|
getBlockNodeIdMapping(&nimap, tmp_nodes, m_gamedef->ndef(), size);
|
||||||
|
|
||||||
buf = MapNode::serializeBulk(version, tmp_nodes, nodecount,
|
buf = MapNode::serializeBulk(version, tmp_nodes.get(), nodecount,
|
||||||
content_width, params_width, m_is_mono_block);
|
content_width, params_width, m_is_mono_block);
|
||||||
delete[] tmp_nodes;
|
|
||||||
|
|
||||||
// write timestamp and node/id mapping first
|
// write timestamp and node/id mapping first
|
||||||
if (version >= 29) {
|
if (version >= 29) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue