diff options
| author | William Wilgus <me.theuser@yahoo.com> | 2018-11-11 18:27:19 -0500 |
|---|---|---|
| committer | William Wilgus <me.theuser@yahoo.com> | 2019-07-11 00:31:41 +0200 |
| commit | c6fcb1cf45b249b059c2d53a062f9a6c7f449047 (patch) | |
| tree | 229eacd12461605a8320eb7590ff83eea13538d6 /apps/plugins/lua/lstring.h | |
| parent | 42240f6990156fb907a7dce7258be2f1235fab44 (diff) | |
| download | rockbox-c6fcb1cf45b249b059c2d53a062f9a6c7f449047.zip rockbox-c6fcb1cf45b249b059c2d53a062f9a6c7f449047.tar.gz rockbox-c6fcb1cf45b249b059c2d53a062f9a6c7f449047.tar.bz2 rockbox-c6fcb1cf45b249b059c2d53a062f9a6c7f449047.tar.xz | |
lua inbinary strings
Allows saving of ram by reusing strings already stored in the binary
and storing a pointer instead of malloc and copy to get them inside
the lua state
Saves about 1.5K overall
Derivative of work by bogdanm
RAM optimizations: pseudo RO strings, functions in Flash
https://github.com/elua/elua/commit/d54659b5723bcd2b1e3900362398c72c18a9aa0b
Change-Id: I21d6dcfa32523877efd9f70fb0f88f2a02872649
Diffstat (limited to 'apps/plugins/lua/lstring.h')
| -rw-r--r-- | apps/plugins/lua/lstring.h | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/apps/plugins/lua/lstring.h b/apps/plugins/lua/lstring.h index c88e4c1..8ca69b8 100644 --- a/apps/plugins/lua/lstring.h +++ b/apps/plugins/lua/lstring.h @@ -12,20 +12,29 @@ #include "lobject.h" #include "lstate.h" - -#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) +/* ROCKLUA ADDED */ +#define TSTR_INBLOB 0 /* string will be allocated at end of tstring struct */ +#define TSTR_INBIN 1 /* string is static within binary, pointer stored */ +#define TSTR_FIXED 2 /* string won't be collected for duration of L state */ +#define TSTR_CHKSZ 4 /* luaS_newllocstr shall determine size of string */ +#define TSTR_ISLIT 8 | TSTR_INBIN /* literal string static within binary */ +#define sizetstring(t, l) (sizeof(union TString) + (testbits((t), TSTR_INBIN) ? \ + sizeof(const char **) : ((l)+1)*sizeof(char))) #define sizeudata(u) (sizeof(union Udata)+(u)->len) -#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) -#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ - (sizeof(s)/sizeof(char))-1)) +#define luaS_new(L, s) (luaS_newllocstr(L, s, 0, TSTR_INBLOB | TSTR_CHKSZ)) +#define luaS_newlstr(L, s, len) (luaS_newllocstr(L, s, len, TSTR_INBLOB)) +#define luaS_newlloc(L, s, t) (luaS_newllocstr(L, s, 0, ((t) | TSTR_CHKSZ))) +#define luaS_newliteral(L, s) (luaS_newllocstr(L, "" s, \ + (sizeof(s)/sizeof(char))-1, TSTR_ISLIT)) #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) LUAI_FUNC void luaS_resize (lua_State *L, int newsize); LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); -LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); - +/* ROCKLUA ADDED */ +LUAI_FUNC TString *luaS_newllocstr (lua_State *L, + const char *str, size_t l, char type); #endif |