Re #4502: Removed cache in Lua rotable search, tests have proven it does not speed up search significantly. Scripts that use some function a lot can use simple local variable to store pointer to the function - simpler and faster that cache.
This commit is contained in:
-24
@@ -35,24 +35,6 @@ static luaR_result luaR_findkey(const void * where, const char * key, int type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char luaR_cachedName[LUA_MAX_ROTABLE_NAME + 1] = {0};
|
|
||||||
TValue luaR_cachedValue;
|
|
||||||
|
|
||||||
static inline void luaR_saveLastFoundGlobal(const char * name, const TValue * val)
|
|
||||||
{
|
|
||||||
strcpy(luaR_cachedName, name);
|
|
||||||
luaR_cachedValue = *val;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline luaR_result luaR_checkLastFoundGlobal(const char * name, TValue * val)
|
|
||||||
{
|
|
||||||
if (!strcmp(luaR_cachedName, name)) {
|
|
||||||
*val = luaR_cachedValue;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find a global "read only table" in the constant lua_rotable array */
|
/* Find a global "read only table" in the constant lua_rotable array */
|
||||||
luaR_result luaR_findglobal(const char * name, TValue * val) {
|
luaR_result luaR_findglobal(const char * name, TValue * val) {
|
||||||
unsigned i;
|
unsigned i;
|
||||||
@@ -60,21 +42,15 @@ luaR_result luaR_findglobal(const char * name, TValue * val) {
|
|||||||
TRACE_LUA_INTERNALS("luaR_findglobal('%s') = NAME TOO LONG", name);
|
TRACE_LUA_INTERNALS("luaR_findglobal('%s') = NAME TOO LONG", name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (luaR_checkLastFoundGlobal(name, val)){
|
|
||||||
TRACE_LUA_INTERNALS("luaR_findglobal('%s') = CACHED", name);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
for (i=0; lua_rotable[i].name; i++) {
|
for (i=0; lua_rotable[i].name; i++) {
|
||||||
void * table = (void *)(&lua_rotable[i]);
|
void * table = (void *)(&lua_rotable[i]);
|
||||||
if (!strcmp(lua_rotable[i].name, name)) {
|
if (!strcmp(lua_rotable[i].name, name)) {
|
||||||
setrvalue(val, table);
|
setrvalue(val, table);
|
||||||
luaR_saveLastFoundGlobal(name, val);
|
|
||||||
TRACE_LUA_INTERNALS("luaR_findglobal('%s') = TABLE %p (%s)", name, table, lua_rotable[i].name);
|
TRACE_LUA_INTERNALS("luaR_findglobal('%s') = TABLE %p (%s)", name, table, lua_rotable[i].name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!strncmp(lua_rotable[i].name, "__", 2)) {
|
if (!strncmp(lua_rotable[i].name, "__", 2)) {
|
||||||
if (luaR_findentry(table, name, val)) {
|
if (luaR_findentry(table, name, val)) {
|
||||||
// luaR_saveLastFoundGlobal(name, val);
|
|
||||||
TRACE_LUA_INTERNALS("luaR_findglobal('%s') = FOUND in table '%s'", name, lua_rotable[i].name);
|
TRACE_LUA_INTERNALS("luaR_findglobal('%s') = FOUND in table '%s'", name, lua_rotable[i].name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user