aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2021-06-23 14:36:44 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2021-06-23 16:32:48 +0200
commit538004ba5f4e280f5d79af67b4f9dcc8124d4f16 (patch)
tree41077ce267d2f43b2e3e354923acc3cfaf2739e7 /core
parent8663c64e47b96c7c03fc539766a4487ec94b39c2 (diff)
Introduce `read_slice`, make `read_u8` use it.
Diffstat (limited to 'core')
-rw-r--r--core/compress/common.odin22
1 files changed, 21 insertions, 1 deletions
diff --git a/core/compress/common.odin b/core/compress/common.odin
index 2a2ee8172..83caabb7b 100644
--- a/core/compress/common.odin
+++ b/core/compress/common.odin
@@ -123,8 +123,22 @@ Code_Buffer :: struct #packed {
This simplifies end-of-stream handling where bits may be left in the bit buffer.
*/
+read_slice :: #force_inline proc(c: ^Context, size: int) -> (res: []u8, err: io.Error) {
+ when #config(TRACY_ENABLE, false) { tracy.ZoneN("Read Slice"); }
+
+ b := make([]u8, size, context.temp_allocator);
+
+ _, e := c.input->impl_read(b[:]);
+ if e != .None {
+ return []u8{}, e;
+ }
+
+ return b, .None;
+}
+
read_data :: #force_inline proc(c: ^Context, $T: typeid) -> (res: T, err: io.Error) {
when #config(TRACY_ENABLE, false) { tracy.ZoneN("Read Data"); }
+
when size_of(T) <= 128 {
b: [size_of(T)]u8;
} else {
@@ -141,7 +155,13 @@ read_data :: #force_inline proc(c: ^Context, $T: typeid) -> (res: T, err: io.Err
read_u8 :: #force_inline proc(z: ^Context) -> (res: u8, err: io.Error) {
when #config(TRACY_ENABLE, false) { tracy.ZoneN("Read u8"); }
- return read_data(z, u8);
+
+ b, e := read_slice(z, 1);
+ if e == .None {
+ return b[0], .None;
+ } else {
+ return 0, e;
+ }
}
peek_data :: #force_inline proc(c: ^Context, $T: typeid) -> (res: T, err: io.Error) {