Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

lua optimize current_path function

frees up around 500 bytes by using the builtin string functionality

Change-Id: Icd4ec921d3fec339b8a4b7f80c9c63d51d4c101c

+13 -24
+4 -1
apps/plugins/lua/loadlib.c
··· 54 54 55 55 static const char *findfile (lua_State *L, const char *name, 56 56 const char *pname) { 57 - const char *path, *current_path = get_current_path(L, 2); 57 + get_current_path(L, 2); 58 + const char *current_path = lua_tostring(L, -1); 59 + const char *path; 60 + 58 61 name = luaL_gsub(L, name, ".", LUA_DIRSEP); 59 62 lua_getfield(L, LUA_ENVIRONINDEX, pname); 60 63 path = lua_tostring(L, -1);
+7 -15
apps/plugins/lua/rockaux.c
··· 73 73 return rb->strcmp(str1, str2); 74 74 } 75 75 76 - const char* get_current_path(lua_State *L, int level) 76 + int get_current_path(lua_State *L, int level) 77 77 { 78 - static char buffer[MAX_PATH]; 79 78 lua_Debug ar; 80 79 81 80 if(lua_getstack(L, level, &ar)) ··· 84 83 and write it to dest. */ 85 84 lua_getinfo(L, "S", &ar); 86 85 87 - char* curfile = (char*) &ar.source[1]; 88 - char* pos = rb->strrchr(curfile, '/'); 86 + const char* curfile = &ar.source[1]; 87 + const char* pos = rb->strrchr(curfile, '/'); 89 88 if(pos != NULL) 90 89 { 91 - unsigned int len = (unsigned int)(pos - curfile); 92 - len = len + 1 > sizeof(buffer) ? sizeof(buffer) - 1 : len; 93 - 94 - if(len > 0) 95 - memcpy(buffer, curfile, len); 96 - 97 - buffer[len] = '/'; 98 - buffer[len+1] = '\0'; 99 - 100 - return buffer; 90 + lua_pushlstring (L, curfile, pos - curfile + 1); 91 + return 1; 101 92 } 102 93 } 103 94 104 - return NULL; 95 + lua_pushnil(L); 96 + return 1; 105 97 }
+1 -7
apps/plugins/lua/rocklib.c
··· 194 194 195 195 RB_WRAP(current_path) 196 196 { 197 - const char *current_path = get_current_path(L, 1); 198 - if(current_path != NULL) 199 - lua_pushstring(L, current_path); 200 - else 201 - lua_pushnil(L); 202 - 203 - return 1; 197 + return get_current_path(L, 1); 204 198 } 205 199 206 200 static void fill_text_message(lua_State *L, struct text_message * message,
+1 -1
apps/plugins/lua/rocklib.h
··· 46 46 }; 47 47 48 48 LUALIB_API int (luaopen_rock) (lua_State *L); 49 - const char* get_current_path(lua_State *L, int level); 49 + int get_current_path(lua_State *L, int level); 50 50 51 51 #endif /* _ROCKLIB_H_ */ 52 52