From 319f38aee3ebe44d106df343004c62d93a7dff04 Mon Sep 17 00:00:00 2001 From: arslee07 Date: Wed, 15 May 2024 13:10:57 +0900 Subject: [PATCH] Fixed arrays scanning; sped up byte array scanning --- format/nbt/load.ha | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/format/nbt/load.ha b/format/nbt/load.ha index 3ce23df..a5dce4c 100644 --- a/format/nbt/load.ha +++ b/format/nbt/load.ha @@ -61,22 +61,24 @@ fn scan_double(h: io::handle) (f64 | error) = { fn scan_byte_array(h: io::handle) ([]i8 | error) = { let length = scan_int(h)?: size; - let buf = alloc([0i8...], length); - for (let i = 0z; i < length; i += 1) { - match (scan_byte(h)) { - case let err: error => { - free(buf); - return err; - }; - case let val: i8 => - buf[i] = val; - }; + + if (length == 0) { + return []: []i8; }; + + let buf = alloc([0i8...], length); + scan_buf(h, buf: []u8)?; + return buf; }; fn scan_int_array(h: io::handle) ([]i32 | error) = { let length = scan_int(h)?: size; + + if (length == 0) { + return []: []i32; + }; + let buf = alloc([0i32...], length); for (let i = 0z; i < length; i += 1) { match (scan_int(h)) { @@ -93,6 +95,11 @@ fn scan_int_array(h: io::handle) ([]i32 | error) = { fn scan_long_array(h: io::handle) ([]i64 | error) = { let length = scan_int(h)?: size; + + if (length == 0) { + return []: []i64; + }; + let buf = alloc([0i64...], length); for (let i = 0z; i < length; i += 1) { @@ -112,6 +119,11 @@ fn scan_long_array(h: io::handle) ([]i64 | error) = { fn scan_list(h: io::handle) (list | error) = { let typ = scan_type(h)?; let length = scan_int(h)?: size; + + if (length == 0) { + return (tagtype::END, []: []payload); + }; + let list: []payload = alloc([end...], length); for (let i = 0z; i < length; i += 1) { -- 2.45.2