Reduce lookups into stack indexes
This commit is contained in:
parent
16c4a11990
commit
34a2001a7b
@ -620,7 +620,7 @@ namespace chaiscript
|
||||
/// Searches the current stack for an object of the given name
|
||||
/// includes a special overload for the _ place holder object to
|
||||
/// ensure that it is always in scope.
|
||||
Boxed_Value get_object(const std::string &name, std::atomic_uint_fast32_t &t_loc) const
|
||||
Boxed_Value get_object(const std::string &name, std::atomic_uint_fast32_t &t_loc, Stack_Holder &t_holder) const
|
||||
{
|
||||
enum class Loc : uint_fast32_t {
|
||||
located = 0x80000000,
|
||||
@ -633,7 +633,7 @@ namespace chaiscript
|
||||
|
||||
if (loc == 0)
|
||||
{
|
||||
auto &stack = get_stack_data();
|
||||
auto &stack = get_stack_data(t_holder);
|
||||
|
||||
// Is it in the stack?
|
||||
for (auto stack_elem = stack.rbegin(); stack_elem != stack.rend(); ++stack_elem)
|
||||
@ -652,7 +652,7 @@ namespace chaiscript
|
||||
|
||||
t_loc = static_cast<uint_fast32_t>(Loc::located);
|
||||
} else if (loc & static_cast<uint_fast32_t>(Loc::is_local)) {
|
||||
auto &stack = get_stack_data();
|
||||
auto &stack = get_stack_data(t_holder);
|
||||
|
||||
return stack[stack.size() - 1 - ((loc & static_cast<uint_fast32_t>(Loc::stack_mask)) >> 16)][loc & static_cast<uint_fast32_t>(Loc::loc_mask)].second;
|
||||
}
|
||||
@ -1528,6 +1528,10 @@ namespace chaiscript
|
||||
m_engine.get().add_object(t_name, std::move(obj), m_stack_holder.get());
|
||||
}
|
||||
|
||||
Boxed_Value get_object(const std::string &t_name, std::atomic_uint_fast32_t &t_loc) const {
|
||||
return m_engine.get().get_object(t_name, t_loc, m_stack_holder.get());
|
||||
}
|
||||
|
||||
private:
|
||||
std::reference_wrapper<Dispatch_Engine> m_engine;
|
||||
std::reference_wrapper<Stack_Holder> m_stack_holder;
|
||||
|
@ -168,7 +168,7 @@ namespace chaiscript
|
||||
return m_value;
|
||||
} else {
|
||||
try {
|
||||
return t_ss->get_object(this->text, m_loc);
|
||||
return t_ss.get_object(this->text, m_loc);
|
||||
}
|
||||
catch (std::exception &) {
|
||||
throw exception::eval_error("Can not find object: " + this->text);
|
||||
|
Loading…
x
Reference in New Issue
Block a user