Selene
Selene copied to clipboard
Implement Selector.h without using _get and _put as std::functions
The _get and _put lambdas can be replaced by member functions and member variables so they are fully inlineable and occupy fewer instructions.
Regarding https://github.com/jeremyong/Selene/pull/105#issuecomment-147492598: I see two kinds of lambdas in use. They differ only in the type used to index tables: string or int.
To replace std::function for _get and _put with member functions boils down to the question how to store those different keys inline in the Selector and its member variable _traversal.
One that comes to mind is to use luaL_ref. Then we only need to store plain ints or sel::detail::LuaRefs within the Selector. We additionally would set in place the infrastructure to enable more types as keys.
To get rid of std::function for the member variable _functor seems not that easy. It stores all parameters for the call to be invoked and therefore has to be dynamically allocated. We could write our own type erasure for this case, but that is what std::function is good at, is it?
std::function is indeed good at type erasure but it can make confuse the optimizer a bit when it comes to instruction inlining (in contrast to lambdas).