koreader/koreader-base — pull request #46 by hwhw (2013-08-16 16:15:37+00:00)
Title: Migration of "util" module to use Luajit's FFI

As a first exemplary migration, the "util" module is migrated to use Luajit's FFI.

Not a lot of speed gained, probably, but it shows how modules should be migrated.
Note the creation of _local_ variables.

Ideally, we should migrate all our code to not use the global namespace at all. Luajit can optimize the access only if it does not have to look up data in the global namespace. So I will focus next on the code in "koreader" and make it local (and change the calls to "require" accordingly).

I think the "kobolight" module is also an easy candidate for the FFI. Others are a bit harder. Note that no calls from FFI into Lua-C-API modules are allowed (you can't pass a valid lua_state via FFI). Of course plain Lua calls to C-API modules are no problem (it works as it always did). If you don't understand what I want to say with this, don't bother. You'll see if you ever try to migrate something that uses blitbuffers, though :-)