class Subroutine : public Value { | |
public: | |
template<typename F> | |
explicit Subroutine(F slow) | |
: slow(std::move(slow)), fast(), fastAvailable(false) { } | |
boost::intrusive_ptr<Value> operator()(VM& vm, std::size_t argc, Value** argv) { | |
if (fastAvailable) { | |
return fast(vm, argc, argv); | |
} else { | |
return slow(vm, argc, argv); | |
} | |
} | |
std::function<boost::intrusive_ptr<Value>(VM&, std::size_t, Value**)> slow; | |
std::function<boost::intrusive_ptr<Value>(VM&, std::size_t, Value**)> fast; | |
std::atomic<bool> fastAvailable; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment