mirror of
https://github.com/minetest/minetest.git
synced 2024-12-23 14:42:24 +01:00
Optimize MapNode::serializeBulk
before serializeBulk [us] __________________________ 9047x 9.363 after serializeBulk [us] __________________________ 8458x 1.214
This commit is contained in:
parent
4027e08cc8
commit
2af5191070
@ -708,15 +708,17 @@ Buffer<u8> MapNode::serializeBulk(int version,
|
||||
|
||||
Buffer<u8> databuf(nodecount * (content_width + params_width));
|
||||
|
||||
u32 start1 = content_width * nodecount;
|
||||
u32 start2 = (content_width + 1) * nodecount;
|
||||
// Writing to the buffer linearly is faster
|
||||
u8 *p = &databuf[0];
|
||||
for (u32 i = 0; i < nodecount; i++, p += 2)
|
||||
writeU16(p, nodes[i].param0);
|
||||
|
||||
for (u32 i = 0; i < nodecount; i++, p++)
|
||||
writeU8(p, nodes[i].param1);
|
||||
|
||||
for (u32 i = 0; i < nodecount; i++, p++)
|
||||
writeU8(p, nodes[i].param2);
|
||||
|
||||
// Serialize content
|
||||
for (u32 i = 0; i < nodecount; i++) {
|
||||
writeU16(&databuf[i * 2], nodes[i].param0);
|
||||
writeU8(&databuf[start1 + i], nodes[i].param1);
|
||||
writeU8(&databuf[start2 + i], nodes[i].param2);
|
||||
}
|
||||
return databuf;
|
||||
}
|
||||
|
||||
|
@ -291,7 +291,7 @@ inline v3f readV3F32(const u8 *data)
|
||||
|
||||
inline void writeU8(u8 *data, u8 i)
|
||||
{
|
||||
data[0] = (i >> 0) & 0xFF;
|
||||
data[0] = i;
|
||||
}
|
||||
|
||||
inline void writeS8(u8 *data, s8 i)
|
||||
|
Loading…
Reference in New Issue
Block a user