Compare commits

..

2 Commits

Author SHA1 Message Date
e3a8063124 calling nbt_primsize actually takes up more lines than if I didn't. 2025-08-19 11:07:13 +02:00
10a2aca0a5 fix: remove recursive functions and improve (theoretical) performance
note that lists are no longer handled here, this will be re-implemented
in a newer commit. The basic functionality for compound/end and other
tags are there, though.
2025-08-18 14:35:05 +02:00

View File

@@ -34,20 +34,19 @@ const u8 *nbt_nexttag(const u8 *restrict buf) {
mems = 0;
switch (*tag) {
case NBT_I8:
case NBT_I16:
case NBT_I32:
case NBT_F32:
case NBT_I64:
case NBT_F64:
ptr += nbt_primsize(*buf);
break;
case NBT_I8: ptr += 1; break;
case NBT_I16: ptr += 2; break;
case NBT_I32: // fall through
case NBT_F32: ptr += 4; break;
case NBT_I64: // fall through
case NBT_F64: ptr += 8; break;
case NBT_ARR_I64: mems += sizeof(i64) - sizeof(i32); __attribute__((fallthrough));
case NBT_ARR_I32: mems += sizeof(i32) - sizeof(i8); __attribute__((fallthrough));
case NBT_ARR_I8: ptr += (mems + 1) * (i32)be32toh(*(u32 *)(ptr)) + 4; break;
case NBT_STR: ptr += be16toh(*(u16 *)(ptr)) + 2; break;
case NBT_END: dpt--; break;
case NBT_END: dpt--; break;
case NBT_COMPOUND: dpt++; break;
// TODO: handle (compound) lists somehow