[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Using Lua's string interning for faster compares?
- From: Peter Odding <peter@...>
- Date: Wed, 18 Jan 2012 20:08:54 +0100
When I write modules to wrap C++ objects, they usually have a __index
method that does a lot of string comparing, like:
if(!strcmp(key, "foo")) lua_pushcfunction(L, obj_method_foo);
else if(!strcmp(key, "bar")) lua_pushcfunction(L, obj_method_bar);
etc... I'm not sure if compilers can optimize this, but doing all
those strcmp()s every time a method/field is looked up seems terribly
I've attached the template I use for such occasions.
Alternatively, re2c does the same thing: http://re2c.org/ (for simple
use cases like matching a string against one of several predefined