Skip to content

Commit 56bf867

Browse files
sapiersapier
sapier
authored and
sapier
committed
Use memset for flag initialization (compiler optimization is way better)
use temp variables instead of recalculating array index
1 parent 496cb11 commit 56bf867

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/voxel.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,23 +183,24 @@ void VoxelManipulator::addArea(VoxelArea area)
183183

184184
// Allocate and clear new data
185185
MapNode *new_data = new MapNode[new_size];
186+
assert(new_data);
186187
u8 *new_flags = new u8[new_size];
187-
for(s32 i=0; i<new_size; i++)
188-
{
189-
new_flags[i] = VOXELFLAG_NOT_LOADED;
190-
}
188+
assert(new_flags);
189+
memset(new_flags, VOXELFLAG_NOT_LOADED, new_size);
191190

192191
// Copy old data
193192

194193
for(s32 z=m_area.MinEdge.Z; z<=m_area.MaxEdge.Z; z++)
195194
for(s32 y=m_area.MinEdge.Y; y<=m_area.MaxEdge.Y; y++)
196195
for(s32 x=m_area.MinEdge.X; x<=m_area.MaxEdge.X; x++)
197196
{
197+
unsigned int old_index = m_area.index(x,y,z);
198198
// If loaded, copy data and flags
199-
if((m_flags[m_area.index(x,y,z)] & VOXELFLAG_NOT_LOADED) == false)
199+
if((m_flags[old_index] & VOXELFLAG_NOT_LOADED) == false)
200200
{
201-
new_data[new_area.index(x,y,z)] = m_data[m_area.index(x,y,z)];
202-
new_flags[new_area.index(x,y,z)] = m_flags[m_area.index(x,y,z)];
201+
unsigned int new_index = new_area.index(x,y,z);
202+
new_data[new_index] = m_data[old_index];
203+
new_flags[new_index] = m_flags[old_index];
203204
}
204205
}
205206

0 commit comments

Comments
 (0)