diff options
| -rw-r--r-- | llimits.h | 11 | ||||
| -rw-r--r-- | lstate.h | 4 | ||||
| -rw-r--r-- | lstring.c | 38 | ||||
| -rw-r--r-- | ltests.h | 6 |
4 files changed, 36 insertions, 23 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llimits.h,v 1.136 2015/07/15 15:57:13 roberto Exp roberto $ | 2 | ** $Id: llimits.h,v 1.137 2015/09/08 16:53:56 roberto Exp roberto $ |
| 3 | ** Limits, basic types, and some other 'installation-dependent' definitions | 3 | ** Limits, basic types, and some other 'installation-dependent' definitions |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -190,10 +190,13 @@ typedef unsigned long Instruction; | |||
| 190 | 190 | ||
| 191 | 191 | ||
| 192 | /* | 192 | /* |
| 193 | ** Size of cache for strings in the API (better be a prime) | 193 | ** Size of cache for strings in the API. 'N' is the number of |
| 194 | ** sets (better be a prime) and "M" is the size of each set (M == 1 | ||
| 195 | ** makes a direct cache.) | ||
| 194 | */ | 196 | */ |
| 195 | #if !defined(STRCACHE_SIZE) | 197 | #if !defined(STRCACHE_N) |
| 196 | #define STRCACHE_SIZE 127 | 198 | #define STRCACHE_N 63 |
| 199 | #define STRCACHE_M 2 | ||
| 197 | #endif | 200 | #endif |
| 198 | 201 | ||
| 199 | 202 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.h,v 2.123 2015/07/04 16:33:17 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.124 2015/09/08 15:41:05 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -140,7 +140,7 @@ typedef struct global_State { | |||
| 140 | TString *memerrmsg; /* memory-error message */ | 140 | TString *memerrmsg; /* memory-error message */ |
| 141 | TString *tmname[TM_N]; /* array with tag-method names */ | 141 | TString *tmname[TM_N]; /* array with tag-method names */ |
| 142 | struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */ | 142 | struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */ |
| 143 | TString *strcache[STRCACHE_SIZE][1]; /* cache for strings in API */ | 143 | TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */ |
| 144 | } global_State; | 144 | } global_State; |
| 145 | 145 | ||
| 146 | 146 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 2.51 2015/09/08 15:41:05 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 2.52 2015/09/17 15:51:05 roberto Exp roberto $ |
| 3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -92,11 +92,12 @@ void luaS_resize (lua_State *L, int newsize) { | |||
| 92 | ** a non-collectable string.) | 92 | ** a non-collectable string.) |
| 93 | */ | 93 | */ |
| 94 | void luaS_clearcache (global_State *g) { | 94 | void luaS_clearcache (global_State *g) { |
| 95 | int i; | 95 | int i, j; |
| 96 | for (i = 0; i < STRCACHE_SIZE; i++) { | 96 | for (i = 0; i < STRCACHE_N; i++) |
| 97 | if (iswhite(g->strcache[i][0])) /* will entry be collected? */ | 97 | for (j = 0; j < STRCACHE_M; j++) { |
| 98 | g->strcache[i][0] = g->memerrmsg; /* replace it with something fixed */ | 98 | if (iswhite(g->strcache[i][j])) /* will entry be collected? */ |
| 99 | } | 99 | g->strcache[i][j] = g->memerrmsg; /* replace it with something fixed */ |
| 100 | } | ||
| 100 | } | 101 | } |
| 101 | 102 | ||
| 102 | 103 | ||
| @@ -105,13 +106,14 @@ void luaS_clearcache (global_State *g) { | |||
| 105 | */ | 106 | */ |
| 106 | void luaS_init (lua_State *L) { | 107 | void luaS_init (lua_State *L) { |
| 107 | global_State *g = G(L); | 108 | global_State *g = G(L); |
| 108 | int i; | 109 | int i, j; |
| 109 | luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ | 110 | luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ |
| 110 | /* pre-create memory-error message */ | 111 | /* pre-create memory-error message */ |
| 111 | g->memerrmsg = luaS_newliteral(L, MEMERRMSG); | 112 | g->memerrmsg = luaS_newliteral(L, MEMERRMSG); |
| 112 | luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ | 113 | luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ |
| 113 | for (i = 0; i < STRCACHE_SIZE; i++) /* fill cache with valid strings */ | 114 | for (i = 0; i < STRCACHE_N; i++) /* fill cache with valid strings */ |
| 114 | g->strcache[i][0] = g->memerrmsg; | 115 | for (j = 0; j < STRCACHE_M; j++) |
| 116 | g->strcache[i][j] = g->memerrmsg; | ||
| 115 | } | 117 | } |
| 116 | 118 | ||
| 117 | 119 | ||
| @@ -205,15 +207,19 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
| 205 | ** check hits. | 207 | ** check hits. |
| 206 | */ | 208 | */ |
| 207 | TString *luaS_new (lua_State *L, const char *str) { | 209 | TString *luaS_new (lua_State *L, const char *str) { |
| 208 | unsigned int i = point2uint(str) % STRCACHE_SIZE; /* hash */ | 210 | unsigned int i = point2uint(str) % STRCACHE_N; /* hash */ |
| 211 | int j; | ||
| 209 | TString **p = G(L)->strcache[i]; | 212 | TString **p = G(L)->strcache[i]; |
| 210 | if (strcmp(str, getstr(p[0])) == 0) /* hit? */ | 213 | for (j = 0; j < STRCACHE_M; j++) { |
| 211 | return p[0]; /* that it is */ | 214 | if (strcmp(str, getstr(p[j])) == 0) /* hit? */ |
| 212 | else { /* normal route */ | 215 | return p[j]; /* that is it */ |
| 213 | TString *s = luaS_newlstr(L, str, strlen(str)); | ||
| 214 | p[0] = s; | ||
| 215 | return s; | ||
| 216 | } | 216 | } |
| 217 | /* normal route */ | ||
| 218 | for (j = STRCACHE_M - 1; j > 0; j--) | ||
| 219 | p[j] = p[j - 1]; /* move out last element */ | ||
| 220 | /* new element is first in the list */ | ||
| 221 | p[0] = luaS_newlstr(L, str, strlen(str)); | ||
| 222 | return p[0]; | ||
| 217 | } | 223 | } |
| 218 | 224 | ||
| 219 | 225 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.h,v 2.47 2014/12/26 14:44:44 roberto Exp roberto $ | 2 | ** $Id: ltests.h,v 2.48 2015/06/18 14:27:44 roberto Exp roberto $ |
| 3 | ** Internal Header for Debugging of the Lua Implementation | 3 | ** Internal Header for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -118,5 +118,9 @@ LUA_API void *debug_realloc (void *ud, void *block, | |||
| 118 | #undef LUAI_USER_ALIGNMENT_T | 118 | #undef LUAI_USER_ALIGNMENT_T |
| 119 | #define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; } | 119 | #define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; } |
| 120 | 120 | ||
| 121 | |||
| 122 | #define STRCACHE_N 23 | ||
| 123 | #define STRCACHE_M 5 | ||
| 124 | |||
| 121 | #endif | 125 | #endif |
| 122 | 126 | ||
