Skip to content

Commit 4aa4303

Browse files
committed
refactor: remove a layer of indirection when accessing the scopes storage
1 parent 9cfc327 commit 4aa4303

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

include/Ark/VM/ScopeView.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace Ark::internal
4040
* @param storage pointer to the shared scope storage
4141
* @param start first free starting position
4242
*/
43-
ScopeView(std::array<pair_t, ScopeStackSize>* storage, std::size_t start) noexcept;
43+
ScopeView(pair_t* storage, std::size_t start) noexcept;
4444

4545
/**
4646
* @brief Put a value in the scope
@@ -98,7 +98,7 @@ namespace Ark::internal
9898
*/
9999
[[nodiscard]] inline const pair_t& atPos(const std::size_t i) const noexcept
100100
{
101-
return (*m_storage)[m_start + i];
101+
return m_storage[m_start + i];
102102
}
103103

104104
/**
@@ -126,7 +126,7 @@ namespace Ark::internal
126126
friend class Ark::VM;
127127

128128
private:
129-
std::array<pair_t, ScopeStackSize>* m_storage;
129+
pair_t* m_storage;
130130
std::size_t m_start;
131131
std::size_t m_size;
132132
uint16_t m_min_id; ///< Minimum stored ID, used for a basic bloom filter

include/Ark/VM/VM.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ inline void VM::call(internal::ExecutionContext& context, const uint16_t argc)
332332
const PageAddr_t new_page_pointer = function.pageAddr();
333333

334334
// create dedicated scope
335-
context.locals.emplace_back(&context.scopes_storage, context.locals.back().storageEnd());
335+
context.locals.emplace_back(context.scopes_storage.data(), context.locals.back().storageEnd());
336336
swapStackForFunCall(argc, context);
337337

338338
// store "reference" to the function to speed the recursive functions
@@ -351,7 +351,7 @@ inline void VM::call(internal::ExecutionContext& context, const uint16_t argc)
351351
const PageAddr_t new_page_pointer = c.pageAddr();
352352

353353
// create dedicated scope
354-
context.locals.emplace_back(&context.scopes_storage, context.locals.back().storageEnd());
354+
context.locals.emplace_back(context.scopes_storage.data(), context.locals.back().storageEnd());
355355
// load saved scope
356356
c.refScope().mergeRefInto(context.locals.back());
357357
context.stacked_closure_scopes.back() = c.scopePtr();

src/arkreactor/VM/ScopeView.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Ark::internal
66
{
7-
ScopeView::ScopeView(std::array<pair_t, ScopeStackSize>* storage, const std::size_t start) noexcept :
7+
ScopeView::ScopeView(pair_t* storage, const std::size_t start) noexcept :
88
m_storage(storage), m_start(start), m_size(0), m_min_id(std::numeric_limits<uint16_t>::max()), m_max_id(0)
99
{}
1010

@@ -15,7 +15,7 @@ namespace Ark::internal
1515
if (id > m_max_id)
1616
m_max_id = id;
1717

18-
(*m_storage)[m_start + m_size] = std::make_pair(id, std::move(val));
18+
m_storage[m_start + m_size] = std::make_pair(id, std::move(val));
1919
++m_size;
2020
}
2121

@@ -26,7 +26,7 @@ namespace Ark::internal
2626
if (id > m_max_id)
2727
m_max_id = id;
2828

29-
(*m_storage)[m_start + m_size] = std::make_pair(id, val);
29+
m_storage[m_start + m_size] = std::make_pair(id, val);
3030
++m_size;
3131
}
3232

@@ -42,7 +42,7 @@ namespace Ark::internal
4242

4343
for (std::size_t i = m_start; i < m_start + m_size; ++i)
4444
{
45-
auto& [id, value] = (*m_storage)[i];
45+
auto& [id, value] = m_storage[i];
4646
if (id == id_to_look_for)
4747
return &value;
4848
}
@@ -56,7 +56,7 @@ namespace Ark::internal
5656

5757
for (std::size_t i = m_start; i < m_start + m_size; ++i)
5858
{
59-
auto& [id, value] = (*m_storage)[i];
59+
auto& [id, value] = m_storage[i];
6060
if (id == id_to_look_for)
6161
return &value;
6262
}
@@ -67,7 +67,7 @@ namespace Ark::internal
6767
{
6868
for (std::size_t i = m_start; i < m_start + m_size; ++i)
6969
{
70-
const auto& [id, value] = (*m_storage)[i];
70+
const auto& [id, value] = m_storage[i];
7171
if (value == val)
7272
return id;
7373
}

src/arkreactor/VM/VM.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ namespace Ark
103103
m_exit_code = 0;
104104

105105
context.locals.clear();
106-
context.locals.emplace_back(&context.scopes_storage, 0);
106+
context.locals.emplace_back(context.scopes_storage.data(), 0);
107107

108108
// loading bound stuff
109109
// put them in the global frame if we can, aka the first one
@@ -236,7 +236,7 @@ namespace Ark
236236
ctx->scopes_storage = m_execution_contexts.front()->scopes_storage;
237237
for (const auto& local : m_execution_contexts.front()->locals)
238238
{
239-
auto& scope = ctx->locals.emplace_back(&ctx->scopes_storage, local.m_start);
239+
auto& scope = ctx->locals.emplace_back(ctx->scopes_storage.data(), local.m_start);
240240
scope.m_size = local.m_size;
241241
scope.m_min_id = local.m_min_id;
242242
scope.m_max_id = local.m_max_id;
@@ -922,7 +922,7 @@ namespace Ark
922922

923923
TARGET(CREATE_SCOPE)
924924
{
925-
context.locals.emplace_back(&context.scopes_storage, context.locals.back().storageEnd());
925+
context.locals.emplace_back(context.scopes_storage.data(), context.locals.back().storageEnd());
926926
DISPATCH();
927927
}
928928

0 commit comments

Comments
 (0)