@@ -252,36 +252,33 @@ struct shrmap {
252
252
int n ;
253
253
};
254
254
255
- static struct shrmap * SSM = NULL ;
255
+ static struct shrmap SSM ;
256
256
257
257
LUA_API void
258
258
luaS_initshr () {
259
- struct shrmap * s = malloc (sizeof (* s ));
260
- memset (s , 0 , sizeof (* s ));
259
+ struct shrmap * s = & SSM ;
261
260
int i ;
262
261
for (i = 0 ;i < SHRSTR_SLOT ;i ++ ) {
263
262
rwlock_init (& s -> h [i ].lock );
264
263
}
265
- SSM = s ;
266
264
}
267
265
268
266
LUA_API void
269
267
luaS_exitshr () {
270
268
int i ;
271
269
for (i = 0 ;i < SHRSTR_SLOT ;i ++ ) {
272
- TString * str = SSM -> h [i ].str ;
270
+ TString * str = SSM . h [i ].str ;
273
271
while (str ) {
274
272
TString * next = str -> u .hnext ;
275
273
free (str );
276
274
str = next ;
277
275
}
278
276
}
279
- free (SSM );
280
277
}
281
278
282
279
static TString *
283
280
query_string (unsigned int h , const char * str , lu_byte l ) {
284
- struct shrmap_slot * s = & SSM -> h [HASH_NODE (h )];
281
+ struct shrmap_slot * s = & SSM . h [HASH_NODE (h )];
285
282
rwlock_rlock (& s -> lock );
286
283
TString * ts = s -> str ;
287
284
while (ts ) {
@@ -299,7 +296,7 @@ query_string(unsigned int h, const char *str, lu_byte l) {
299
296
static TString *
300
297
query_ptr (TString * t ) {
301
298
unsigned int h = t -> hash ;
302
- struct shrmap_slot * s = & SSM -> h [HASH_NODE (h )];
299
+ struct shrmap_slot * s = & SSM . h [HASH_NODE (h )];
303
300
rwlock_rlock (& s -> lock );
304
301
TString * ts = s -> str ;
305
302
while (ts ) {
@@ -326,7 +323,7 @@ new_string(unsigned int h, const char *str, lu_byte l) {
326
323
static TString *
327
324
add_string (unsigned int h , const char * str , lu_byte l ) {
328
325
TString * tmp = new_string (h , str , l );
329
- struct shrmap_slot * s = & SSM -> h [HASH_NODE (h )];
326
+ struct shrmap_slot * s = & SSM . h [HASH_NODE (h )];
330
327
rwlock_wlock (& s -> lock );
331
328
TString * ts = s -> str ;
332
329
while (ts ) {
@@ -366,9 +363,9 @@ internshrstr (lua_State *L, const char *str, size_t l) {
366
363
ts = query_string (h0 , str , l );
367
364
if (ts )
368
365
return ts ;
369
- // If SSM-> n greate than 0, add it to SSM
370
- if (SSM -> n > 0 ) {
371
- ATOM_DEC (& SSM -> n );
366
+ // If SSM. n greate than 0, add it to SSM
367
+ if (SSM . n > 0 ) {
368
+ ATOM_DEC (& SSM . n );
372
369
return add_string (h0 , str , l );
373
370
}
374
371
// Else add it to global state (local)
@@ -377,7 +374,7 @@ internshrstr (lua_State *L, const char *str, size_t l) {
377
374
378
375
LUA_API void
379
376
luaS_expandshr (int n ) {
380
- ATOM_ADD (& SSM -> n , n );
377
+ ATOM_ADD (& SSM . n , n );
381
378
}
382
379
383
380
LUAI_FUNC TString *
@@ -430,7 +427,7 @@ luaS_shrinfo(lua_State *L) {
430
427
int i ;
431
428
int len = 0 ;
432
429
for (i = 0 ;i < SHRSTR_SLOT ;i ++ ) {
433
- struct shrmap_slot * s = & SSM -> h [i ];
430
+ struct shrmap_slot * s = & SSM . h [i ];
434
431
getslot (s , & tmp );
435
432
len += tmp .len ;
436
433
if (tmp .len > total .len ) {
@@ -441,6 +438,6 @@ luaS_shrinfo(lua_State *L) {
441
438
lua_pushinteger (L , len );
442
439
lua_pushinteger (L , total .size );
443
440
lua_pushinteger (L , total .len );
444
- lua_pushinteger (L , SSM -> n );
441
+ lua_pushinteger (L , SSM . n );
445
442
return 4 ;
446
443
}
0 commit comments