diff --git a/src/cs_state.cc b/src/cs_state.cc index b9bb8e2..4cbb272 100644 --- a/src/cs_state.cc +++ b/src/cs_state.cc @@ -45,11 +45,17 @@ static void *default_alloc(void *, void *p, size_t, size_t ns) { } ident *internal_state::lookup_ident(std::size_t idx) { + if (idx < MAX_ARGUMENTS) { + return argmap[idx]; + } std::lock_guard l{ident_mtx}; return identmap[idx]; } ident const *internal_state::lookup_ident(std::size_t idx) const { + if (idx < MAX_ARGUMENTS) { + return argmap[idx]; + } std::lock_guard l{ident_mtx}; return identmap[idx]; } @@ -141,7 +147,7 @@ state::state(alloc_func func, void *data) { for (std::size_t i = 0; i < MAX_ARGUMENTS; ++i) { char buf[16]; snprintf(buf, sizeof(buf), "arg%zu", i + 1); - statep->new_ident( + statep->argmap[i] = &statep->new_ident( *this, static_cast(buf), IDENT_FLAG_ARG ); } diff --git a/src/cs_state.hh b/src/cs_state.hh index ac4fa8c..a2c718e 100644 --- a/src/cs_state.hh +++ b/src/cs_state.hh @@ -50,6 +50,7 @@ struct internal_state { allocator_type > idents; std::vector> identmap; + std::array argmap; mutable std::mutex ident_mtx; string_pool *strman; diff --git a/src/cs_vm.cc b/src/cs_vm.cc index 2053259..6b1d51b 100644 --- a/src/cs_vm.cc +++ b/src/cs_vm.cc @@ -133,7 +133,7 @@ any_value exec_alias( std::size_t noff = ts.idstack.size(); for(std::size_t i = 0; i < callargs; i++) { auto &ast = ts.get_astack( - static_cast(ts.istate->lookup_ident(i)) + static_cast(ts.istate->argmap[i]) ); auto &st = ts.idstack.emplace_back(); ast.push(st); @@ -167,14 +167,14 @@ any_value exec_alias( tss.ident_flags = oflags; for (std::size_t i = 0; i < cargs; i++) { tss.get_astack( - static_cast(tss.istate->lookup_ident(i)) + static_cast(tss.istate->argmap[i]) ).pop(); amask[i] = false; } for (; amask.any(); ++cargs) { if (amask[cargs]) { tss.get_astack( - static_cast(tss.istate->lookup_ident(cargs)) + static_cast(tss.istate->argmap[cargs]) ).pop(); amask[cargs] = false; } @@ -202,7 +202,7 @@ any_value exec_code_with_args(thread_state &ts, bcode_ref const &body) { for (std::size_t i = 0; mask.any(); ++i) { if (mask[0]) { auto &ast = ts.get_astack( - static_cast(ts.istate->lookup_ident(i)) + static_cast(ts.istate->argmap[i]) ); auto &st = ts.idstack.emplace_back(); st.next = ast.node; @@ -229,7 +229,7 @@ any_value exec_code_with_args(thread_state &ts, bcode_ref const &body) { for (std::size_t i = 0, nredo = 0; mask2.any(); ++i) { if (mask2[0]) { tss.get_astack( - static_cast(tss.istate->lookup_ident(i)) + static_cast(tss.istate->argmap[i]) ).node = tss.idstack[offn + nredo++].next; } mask2 >>= 1;