-
-
Save rightfold/f4cd1d4f7b876fabf899 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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