diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-01-13 16:06:27 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-01-13 16:06:27 -0200 |
commit | 5981161360e054b8e7e6e670f6ec8d0a2add7f3b (patch) | |
tree | 0199ba9cea7f34488e07fe05743d26e88875681c | |
parent | 763c64be9bcdb3af225f547856af50fcc4cfc544 (diff) | |
download | lua-5981161360e054b8e7e6e670f6ec8d0a2add7f3b.tar.gz lua-5981161360e054b8e7e6e670f6ec8d0a2add7f3b.tar.bz2 lua-5981161360e054b8e7e6e670f6ec8d0a2add7f3b.zip |
small optimizations (?)
-rw-r--r-- | lstring.c | 10 | ||||
-rw-r--r-- | ltable.c | 5 |
2 files changed, 10 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 1.8 1997/12/09 13:35:19 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.9 1997/12/30 19:15:52 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 | */ |
@@ -102,17 +102,21 @@ static TaggedString *insert (char *buff, int tag, stringtable *tb) | |||
102 | { | 102 | { |
103 | TaggedString *ts; | 103 | TaggedString *ts; |
104 | unsigned long h = hash(buff, tag); | 104 | unsigned long h = hash(buff, tag); |
105 | int size = tb->size; | ||
105 | int i; | 106 | int i; |
106 | int j = -1; | 107 | int j = -1; |
107 | if ((long)tb->nuse*3 >= (long)tb->size*2) | 108 | if ((long)tb->nuse*3 >= (long)size*2) { |
108 | grow(tb); | 109 | grow(tb); |
109 | for (i = h%tb->size; (ts = tb->hash[i]) != NULL; i = (i+1)%tb->size) { | 110 | size = tb->size; |
111 | } | ||
112 | for (i = h%size; (ts = tb->hash[i]) != NULL; ) { | ||
110 | if (ts == &EMPTY) | 113 | if (ts == &EMPTY) |
111 | j = i; | 114 | j = i; |
112 | else if ((ts->constindex >= 0) ? /* is a string? */ | 115 | else if ((ts->constindex >= 0) ? /* is a string? */ |
113 | (tag == LUA_T_STRING && (strcmp(buff, ts->str) == 0)) : | 116 | (tag == LUA_T_STRING && (strcmp(buff, ts->str) == 0)) : |
114 | ((tag == ts->u.d.tag || tag == LUA_ANYTAG) && buff == ts->u.d.v)) | 117 | ((tag == ts->u.d.tag || tag == LUA_ANYTAG) && buff == ts->u.d.v)) |
115 | return ts; | 118 | return ts; |
119 | if (++i == size) i=0; | ||
116 | } | 120 | } |
117 | /* not found */ | 121 | /* not found */ |
118 | if (j != -1) /* is there an EMPTY space? */ | 122 | if (j != -1) /* is there an EMPTY space? */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 1.9 1997/12/15 16:17:20 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.10 1998/01/09 14:44:55 roberto Exp roberto $ |
3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -65,7 +65,8 @@ static int present (Hash *t, TObject *key) | |||
65 | if (ttype(rf) != LUA_T_NIL && !luaO_equalObj(key, rf)) { | 65 | if (ttype(rf) != LUA_T_NIL && !luaO_equalObj(key, rf)) { |
66 | int h2 = h%(tsize-2) + 1; | 66 | int h2 = h%(tsize-2) + 1; |
67 | do { | 67 | do { |
68 | h1 = (h1+h2)%tsize; | 68 | h1 += h2; |
69 | if (h1 >= tsize) h1 -= tsize; | ||
69 | rf = ref(node(t, h1)); | 70 | rf = ref(node(t, h1)); |
70 | } while (ttype(rf) != LUA_T_NIL && !luaO_equalObj(key, rf)); | 71 | } while (ttype(rf) != LUA_T_NIL && !luaO_equalObj(key, rf)); |
71 | } | 72 | } |