From 8a4e20dd8de540af8995deeb59f74d997d08667d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 16 Sep 2020 19:20:01 +0200 Subject: [PATCH] Reorder fields on OperandStack --- lib/fizzy/stack.hpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/fizzy/stack.hpp b/lib/fizzy/stack.hpp index 25c4e4ddb..3c1b6a9f3 100644 --- a/lib/fizzy/stack.hpp +++ b/lib/fizzy/stack.hpp @@ -62,17 +62,21 @@ class OperandStack /// The size of the pre-allocated internal storage: 128 bytes. static constexpr auto small_storage_size = 128 / sizeof(Value); - /// The pointer to the top item, or below the stack bottom if stack is empty. + /// The pointer to the top item of the operand stack, + /// or below the stack bottom if stack is empty. /// - /// This pointer always alias m_storage, but it is kept as the first field + /// This pointer always alias m_locals, but it is kept as the first field /// because it is accessed the most. Therefore, it must be initialized - /// in the constructor after the m_storage. + /// in the constructor after the m_locals. Value* m_top; - Value* m_bottom; - + /// The pointer to the beginning of the locals array. + /// This always points to one of the storages. Value* m_locals; + /// The pointer to the bottom of the operand stack. + Value* m_bottom; + /// The pre-allocated internal storage. Value m_small_storage[small_storage_size]; @@ -97,18 +101,16 @@ class OperandStack const auto num_args = args.size(); const auto storage_size_required = num_args + num_local_variables + max_stack_height; - Value* storage; if (storage_size_required <= small_storage_size) { - storage = &m_small_storage[0]; + m_locals = &m_small_storage[0]; } else { m_large_storage = std::make_unique(storage_size_required); - storage = &m_large_storage[0]; + m_locals = &m_large_storage[0]; } - m_locals = storage; m_bottom = m_locals + num_args + num_local_variables; m_top = m_bottom - 1;