perf: write nbt byte arrays in bulk (#2785)

This commit is contained in:
nobuildersnotools
2026-08-29 21:55:45 -04:00
committed by GitHub
parent ed4c4e0fb8
commit 538cea363b

View File

@@ -141,9 +141,11 @@ impl NbtTag {
}
w.write_i32(len as i32)?;
for int in byte_array {
w.write_i8(int)?;
}
// SAFETY: `i8` and `u8` have identical layouts, and the slice is only read.
let bytes = unsafe {
std::slice::from_raw_parts(byte_array.as_ptr().cast::<u8>(), byte_array.len())
};
w.write_slice(bytes)?;
}
Self::String(string) => {
w.write_string(&string)?;