diff --git a/src/mapblock.cpp b/src/mapblock.cpp index d883957625..bbd9e57ac1 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -230,17 +230,16 @@ void MapBlock::copyFrom(const VoxelManipulator &src) tryShrinkNodes(); } -void MapBlock::reallocate(u32 c, MapNode n) +void MapBlock::reallocate(u32 count, MapNode n) { delete[] data; - if (!m_is_mono_block && c == 1) + if (!m_is_mono_block && count == 1) porting::TrackFreedMemory(sizeof(MapNode) * nodecount); - data = new MapNode[c]; - for (u32 i = 0; i < c; i++) - data[i] = n; + data = new MapNode[count]; + std::fill_n(data, count, n); - m_is_mono_block = (c == 1); + m_is_mono_block = (count == 1); } void MapBlock::tryShrinkNodes() @@ -308,7 +307,7 @@ void MapBlock::expireIsAirCache() // Renumbers the content IDs (starting at 0 and incrementing) // Note that there's no technical reason why we *have to* renumber the IDs, // but we do it anyway as it also helps compressability. -static void getBlockNodeIdMapping(NameIdMapping *nimap, const std::unique_ptr &nodes, +static void getBlockNodeIdMapping(NameIdMapping *nimap, MapNode *nodes, const NodeDefManager *nodedef, u32 nodecount) { IdIdMapping &mapping = IdIdMapping::giveClearedThreadLocalInstance(); @@ -429,8 +428,8 @@ void MapBlock::serialize(std::ostream &os_compressed, u8 version, bool disk, int { const size_t size = m_is_mono_block ? 1 : nodecount; auto tmp_nodes = std::make_unique(size); - std::copy(data, data+size, tmp_nodes.get()); - getBlockNodeIdMapping(&nimap, tmp_nodes, m_gamedef->ndef(), size); + std::copy_n(data, size, tmp_nodes.get()); + getBlockNodeIdMapping(&nimap, tmp_nodes.get(), m_gamedef->ndef(), size); buf = MapNode::serializeBulk(version, tmp_nodes.get(), nodecount, content_width, params_width, m_is_mono_block); diff --git a/src/mapblock.h b/src/mapblock.h index 483964db54..c8026abb4a 100644 --- a/src/mapblock.h +++ b/src/mapblock.h @@ -444,7 +444,7 @@ private: void tryShrinkNodes(); // if only a single node is stored, expand storage back to the full array void expandNodesIfNeeded(); - void reallocate(u32 c, MapNode n); + void reallocate(u32 count, MapNode n); /* * PLEASE NOTE: When adding something here be mindful of position and size diff --git a/src/voxel.cpp b/src/voxel.cpp index 2f6204e8ed..7de555e4a6 100644 --- a/src/voxel.cpp +++ b/src/voxel.cpp @@ -217,11 +217,11 @@ void VoxelManipulator::copyFrom(MapNode *src, size_t n_nodes, const VoxelArea& s for (s16 z = 0; z < size.Z; z++) { for (s16 y = 0; y < size.Y; y++) { if (n_nodes == 1) { - std::fill(m_data + i_local, m_data + i_local + size.X, src[0]); + std::fill_n(m_data + i_local, size.X, src[0]); } else { - std::copy(src + i_src, src + i_src + size.X, m_data + i_local); + std::copy_n(src + i_src, size.X, m_data + i_local); } - std::fill(m_flags + i_local, m_flags + i_local + size.X, 0); + std::fill_n(m_flags + i_local, size.X, 0); i_src += src_step; i_local += dest_step; }