diff options
author | William Wilgus <wilgus.william@gmail.com> | 2021-05-11 21:35:41 -0400 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2021-05-19 23:28:35 +0000 |
commit | dcff9b85a3cef778af60ad4426f91262ba815931 (patch) | |
tree | 8f58cd59a2115ac70cd4df6e462ded09c81375fc /apps/plugins/lua/lauxlib.c | |
parent | 0c6217757528b185c3f8628c062a2a688a8adaf8 (diff) | |
download | rockbox-dcff9b85a3cef778af60ad4426f91262ba815931.tar.gz rockbox-dcff9b85a3cef778af60ad4426f91262ba815931.zip |
lua latebound function update
return the nextfunction and nil instead of pairs it allows a faster
return to lua rather than calling the lua function
pcall(fnpairs) from c and returning the result back
into lua to kick off the search
yeah, no clue why I didn't realize that before..
testing in x86 and ARM..
its more RAM efficient to do the initial creation
of the stack in lua code for the __pairs functon
its not faster but being that its a one time hit per
iter creation the reduced churn alone should be worth it
along with a reduced peak RAM usage
fix bug where a failed module can not be reloaded
optimize filetol
fix potential bug in splash scroller when no break character is found
Change-Id: I42c922e07039a19138b97c0d0e80cf3cf2426471
Diffstat (limited to 'apps/plugins/lua/lauxlib.c')
-rw-r--r-- | apps/plugins/lua/lauxlib.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/apps/plugins/lua/lauxlib.c b/apps/plugins/lua/lauxlib.c index acd7e0e636..b8332427f0 100644 --- a/apps/plugins/lua/lauxlib.c +++ b/apps/plugins/lua/lauxlib.c | |||
@@ -268,7 +268,8 @@ static int latebind_func_index(lua_State *L) | |||
268 | const char *name = lua_tostring(L, -1); | 268 | const char *name = lua_tostring(L, -1); |
269 | 269 | ||
270 | lua_pushstring (L, "__latebind");/* basetable;name;__latebind;*/ | 270 | lua_pushstring (L, "__latebind");/* basetable;name;__latebind;*/ |
271 | lua_rawget (L, -3);/* basetable;name;__latebind(t);*/ | 271 | if(lua_istable(L, -3)) |
272 | lua_rawget (L, -3);/* basetable;name;__latebind(t);*/ | ||
272 | 273 | ||
273 | luaL_argcheck(L, lua_istable(L, -3) && lua_istable(L, -1), 1, | 274 | luaL_argcheck(L, lua_istable(L, -3) && lua_istable(L, -1), 1, |
274 | "__latebind table expected"); | 275 | "__latebind table expected"); |
@@ -324,25 +325,31 @@ static int latebind_func_pairs(lua_State *L) | |||
324 | { | 325 | { |
325 | /* basetable @ top of stack 1(basetable)-1 */ | 326 | /* basetable @ top of stack 1(basetable)-1 */ |
326 | luaL_argcheck(L, lua_istable(L, 1), 1, "table expected"); | 327 | luaL_argcheck(L, lua_istable(L, 1), 1, "table expected"); |
327 | lua_getglobal(L, "pairs"); /* function to be called / returned (btable;pairs) */ | ||
328 | 328 | ||
329 | lua_createtable(L, 0, 15); /* btable;pairs;newtable; */ | 329 | #if 0 |
330 | /* clone base table */ | 330 | lua_getglobal(L, "next"); /* function to be called / returned (btable;next) */ |
331 | lua_createtable(L, 0, 15); /* btable;next;newtable; */ | ||
332 | lua_pushnil(L); /* nil name retrieves all unbound latebound functions */ | ||
331 | lua_pushnil(L); /* first key */ | 333 | lua_pushnil(L); /* first key */ |
332 | while(lua_next(L, 1) != 0) { | 334 | #else |
333 | /* (btable;pairs;ntable;k;v) */ | 335 | /* this way is more RAM efficient in testing */ |
336 | if(luaL_dostring(L, "return next, {}, nil, nil")!= 0) | ||
337 | lua_error(L); | ||
338 | #endif | ||
339 | /* (btable;next;ntable;nil;nil) */ | ||
340 | /* clone base table */ | ||
341 | while(lua_next(L, 1) > 0) { | ||
342 | /* (btable;next;ntable;nil;k;v) */ | ||
334 | lua_pushvalue(L, -2); /* dupe key Stk = (..;k;v -> ..k;v;k)*/ | 343 | lua_pushvalue(L, -2); /* dupe key Stk = (..;k;v -> ..k;v;k)*/ |
335 | lua_insert(L, -2); /* Stk = (..k;k;v) */ | 344 | lua_insert(L, -2); /* Stk = (..k;k;v) */ |
336 | lua_rawset(L, 3); /* btable;pairs;ntable;k */ | 345 | lua_rawset(L, -5); /* btable;next;ntable;nil;k */ |
337 | } | 346 | } |
338 | 347 | /* fill the new table with all the latebound functions */ | |
339 | lua_pushnil(L); /*nil name retrieves all unbound late bound functions */ | 348 | /* nil name retrieves all unbound latebound functions */ |
340 | latebind_func_index(L);/* (btable;pairs;ntable;nil) -> (btable;pairs;ntable) */ | 349 | latebind_func_index(L);/* (btable;next;ntable;nil) -> (btable;next;ntable) */ |
341 | 350 | lua_pushnil(L); /*nil initial key for next*/ | |
342 | /* (btable;pairs;ntable) */ | 351 | /* stack = (btable;next;ntable;nil) */ |
343 | lua_call(L, 1, 3); /* pairs(ntable) -> (btable;iter;state;value) */ | 352 | return 3; /*(next,ntable,nil)*/ |
344 | |||
345 | return 3; | ||
346 | } | 353 | } |
347 | 354 | ||
348 | 355 | ||