diff --git a/source/coral/stack.cpp b/source/coral/stack.cpp index 4be80ed..95cba0f 100755 --- a/source/coral/stack.cpp +++ b/source/coral/stack.cpp @@ -73,7 +73,7 @@ export namespace coral { * * *Note*: the [allocator] referenced in the stack must remain valid for the duration of the stack lifetime. */ - template struct small_stack : public stack { + template struct small_stack final : public stack { small_stack(allocator & dynamic_allocator) : dynamic_allocator{dynamic_allocator} {} ~small_stack() override { @@ -255,9 +255,8 @@ export namespace coral { * Readable type for streaming data from a [stack] containing [u8] values. */ struct stack_reader : public reader { - stack_reader(byte_stack const * stack) { + stack_reader(byte_stack const & stack) : stack{stack} { this->cursor = 0; - this->stack = stack; } /** @@ -266,7 +265,7 @@ export namespace coral { expected read(slice const & buffer) override { usize data_written = 0; - this->stack->every([&](u8 byte) -> bool { + this->stack.every([&](u8 byte) -> bool { buffer[data_written] = byte; data_written += 1; @@ -281,23 +280,21 @@ export namespace coral { private: usize cursor {0}; - byte_stack const * stack {nullptr}; + byte_stack const & stack; }; /** * Writable type for appending data to a [contiguous_range] containing [u8] values. */ struct stack_writer : public writer { - stack_writer(byte_stack * stack) { - this->stack = stack; - } + stack_writer(byte_stack & stack) : stack{stack} {} /** * Attempts to write `buffer` to the target stack, returning the number of bytes written or an [io_error] if it * failed to commit `buffer` to the stack memory. */ expected write(slice const & buffer) override { - switch (this->stack->push_all(buffer)) { + switch (this->stack.push_all(buffer)) { case push_result::ok: return buffer.length; case push_result::out_of_memory: return io_error::unavailable; default: unreachable(); @@ -305,6 +302,6 @@ export namespace coral { } private: - byte_stack * stack {nullptr}; + byte_stack & stack; }; }