Not sure it is that much faster. What I would try is to call the strncmp
from the standard C library.
Something like this:
ffi.cdef [[
int strncmp ( const char * str1, const char * str2, size_t num );
]]
local ok = ffi.new("char[3]", "ok")
local reply = ffi.gc(ffi.C.doSomething, ffi.C.freeReply)
assert(ffi.C.strncmp(ok, reply.str, reply.len) == 0)
You may also try to first check that reply.len
is 2 and then call memcmp
instead of strncmp
. It may be a little faster.