diff options
author | William Wilgus <me.theuser@yahoo.com> | 2018-10-13 13:35:01 -0400 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2018-10-15 18:24:10 +0200 |
commit | 07fed9053a476b4c6e5ecd23fc43ec84f4094978 (patch) | |
tree | da366faad51087b2e5000a1d9d3659d5bd1a73a8 /apps/plugins | |
parent | 0b7a8d5afd3d751fd0f6454098bc9fd1d05ee764 (diff) | |
download | rockbox-07fed9053a476b4c6e5ecd23fc43ec84f4094978.tar.gz rockbox-07fed9053a476b4c6e5ecd23fc43ec84f4094978.zip |
lua optimize current_path function
frees up around 500 bytes by using the builtin string functionality
Change-Id: Icd4ec921d3fec339b8a4b7f80c9c63d51d4c101c
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/lua/loadlib.c | 5 | ||||
-rw-r--r-- | apps/plugins/lua/rockaux.c | 22 | ||||
-rw-r--r-- | apps/plugins/lua/rocklib.c | 8 | ||||
-rw-r--r-- | apps/plugins/lua/rocklib.h | 2 |
4 files changed, 13 insertions, 24 deletions
diff --git a/apps/plugins/lua/loadlib.c b/apps/plugins/lua/loadlib.c index 1cc7ebd7db..87873f133f 100644 --- a/apps/plugins/lua/loadlib.c +++ b/apps/plugins/lua/loadlib.c @@ -54,7 +54,10 @@ static const char *pushnexttemplate (lua_State *L, const char *path) { static const char *findfile (lua_State *L, const char *name, const char *pname) { - const char *path, *current_path = get_current_path(L, 2); + get_current_path(L, 2); + const char *current_path = lua_tostring(L, -1); + const char *path; + name = luaL_gsub(L, name, ".", LUA_DIRSEP); lua_getfield(L, LUA_ENVIRONINDEX, pname); path = lua_tostring(L, -1); diff --git a/apps/plugins/lua/rockaux.c b/apps/plugins/lua/rockaux.c index f10a1cb021..b51364f718 100644 --- a/apps/plugins/lua/rockaux.c +++ b/apps/plugins/lua/rockaux.c @@ -73,9 +73,8 @@ int strcoll(const char * str1, const char * str2) return rb->strcmp(str1, str2); } -const char* get_current_path(lua_State *L, int level) +int get_current_path(lua_State *L, int level) { - static char buffer[MAX_PATH]; lua_Debug ar; if(lua_getstack(L, level, &ar)) @@ -84,22 +83,15 @@ const char* get_current_path(lua_State *L, int level) and write it to dest. */ lua_getinfo(L, "S", &ar); - char* curfile = (char*) &ar.source[1]; - char* pos = rb->strrchr(curfile, '/'); + const char* curfile = &ar.source[1]; + const char* pos = rb->strrchr(curfile, '/'); if(pos != NULL) { - unsigned int len = (unsigned int)(pos - curfile); - len = len + 1 > sizeof(buffer) ? sizeof(buffer) - 1 : len; - - if(len > 0) - memcpy(buffer, curfile, len); - - buffer[len] = '/'; - buffer[len+1] = '\0'; - - return buffer; + lua_pushlstring (L, curfile, pos - curfile + 1); + return 1; } } - return NULL; + lua_pushnil(L); + return 1; } diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index 57165a5d15..ffd449e9d4 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c @@ -194,13 +194,7 @@ RB_WRAP(font_getstringsize) RB_WRAP(current_path) { - const char *current_path = get_current_path(L, 1); - if(current_path != NULL) - lua_pushstring(L, current_path); - else - lua_pushnil(L); - - return 1; + return get_current_path(L, 1); } static void fill_text_message(lua_State *L, struct text_message * message, diff --git a/apps/plugins/lua/rocklib.h b/apps/plugins/lua/rocklib.h index 25b5ae1088..b650207e67 100644 --- a/apps/plugins/lua/rocklib.h +++ b/apps/plugins/lua/rocklib.h @@ -46,7 +46,7 @@ struct lua_str_reg { }; LUALIB_API int (luaopen_rock) (lua_State *L); -const char* get_current_path(lua_State *L, int level); +int get_current_path(lua_State *L, int level); #endif /* _ROCKLIB_H_ */ |