diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-08-10 18:36:32 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-08-10 18:36:32 -0300 |
| commit | 5378331f2df1ba5bc3a4dc38f7b3ae53c3f2cbef (patch) | |
| tree | a6812bd7389ac65f84572a4b65e1a767c5b7499a /lstring.c | |
| parent | 894a2646719006489800ea68b0515ab956f8aa62 (diff) | |
| download | lua-5378331f2df1ba5bc3a4dc38f7b3ae53c3f2cbef.tar.gz lua-5378331f2df1ba5bc3a4dc38f7b3ae53c3f2cbef.tar.bz2 lua-5378331f2df1ba5bc3a4dc38f7b3ae53c3f2cbef.zip | |
hash tables may shrink if use rate is too small.
Diffstat (limited to 'lstring.c')
| -rw-r--r-- | lstring.c | 10 |
1 files changed, 3 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 1.13 1998/06/19 16:14:09 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.14 1998/07/27 17:06:17 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 | */ |
| @@ -45,8 +45,7 @@ static unsigned long hash_s (char *s, long l) | |||
| 45 | return h; | 45 | return h; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | static int newsize (stringtable *tb) | 48 | static int newsize (stringtable *tb) { |
| 49 | { | ||
| 50 | int size = tb->size; | 49 | int size = tb->size; |
| 51 | int realuse = 0; | 50 | int realuse = 0; |
| 52 | int i; | 51 | int i; |
| @@ -54,10 +53,7 @@ static int newsize (stringtable *tb) | |||
| 54 | for (i=0; i<size; i++) | 53 | for (i=0; i<size; i++) |
| 55 | if (tb->hash[i] != NULL && tb->hash[i] != &EMPTY) | 54 | if (tb->hash[i] != NULL && tb->hash[i] != &EMPTY) |
| 56 | realuse++; | 55 | realuse++; |
| 57 | if (2*(realuse+1) <= size) /* +1 is the new element */ | 56 | return luaO_redimension((realuse+1)*2); /* +1 is the new element */ |
| 58 | return size; /* don't need to grow, just rehash to clear EMPTYs */ | ||
| 59 | else | ||
| 60 | return luaO_redimension(size); | ||
| 61 | } | 57 | } |
| 62 | 58 | ||
| 63 | 59 | ||
