diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-08-30 17:56:43 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-08-30 17:56:43 -0300 |
| commit | 8c8ad5f3fffae16a751f2419a5972ec7ffd6babf (patch) | |
| tree | db9e7977a263eb91b4c990420af203ce0d4f7d2a /ltable.c | |
| parent | 34a09b65f3b6ef5f7699263b09ad088ec087aca2 (diff) | |
| download | lua-8c8ad5f3fffae16a751f2419a5972ec7ffd6babf.tar.gz lua-8c8ad5f3fffae16a751f2419a5972ec7ffd6babf.tar.bz2 lua-8c8ad5f3fffae16a751f2419a5972ec7ffd6babf.zip | |
better locality of assignment of table values
Diffstat (limited to 'ltable.c')
| -rw-r--r-- | ltable.c | 36 |
1 files changed, 18 insertions, 18 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 1.82 2001/06/26 13:20:45 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.83 2001/07/05 20:31:14 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 | */ |
| @@ -161,10 +161,8 @@ static void rehash (lua_State *L, Hash *t) { | |||
| 161 | setnodevector(L, t, oldsize); /* just rehash; keep the same size */ | 161 | setnodevector(L, t, oldsize); /* just rehash; keep the same size */ |
| 162 | for (i=0; i<oldsize; i++) { | 162 | for (i=0; i<oldsize; i++) { |
| 163 | Node *old = nold+i; | 163 | Node *old = nold+i; |
| 164 | if (ttype(val(old)) != LUA_TNIL) { | 164 | if (ttype(val(old)) != LUA_TNIL) |
| 165 | TObject *v = luaH_set(L, t, key(old)); | 165 | luaH_set(L, t, key(old), val(old)); |
| 166 | setobj(v, val(old)); | ||
| 167 | } | ||
| 168 | } | 166 | } |
| 169 | luaM_freearray(L, nold, oldsize, Node); /* free old array */ | 167 | luaM_freearray(L, nold, oldsize, Node); /* free old array */ |
| 170 | } | 168 | } |
| @@ -206,7 +204,7 @@ static TObject *newkey (lua_State *L, Hash *t, const TObject *key) { | |||
| 206 | else (t->firstfree)--; | 204 | else (t->firstfree)--; |
| 207 | } | 205 | } |
| 208 | rehash(L, t); /* no more free places */ | 206 | rehash(L, t); /* no more free places */ |
| 209 | return luaH_set(L, t, key); /* `rehash' invalidates this insertion */ | 207 | return newkey(L, t, key); /* `rehash' invalidates this insertion */ |
| 210 | } | 208 | } |
| 211 | 209 | ||
| 212 | 210 | ||
| @@ -271,32 +269,34 @@ const TObject *luaH_get (Hash *t, const TObject *key) { | |||
| 271 | } | 269 | } |
| 272 | 270 | ||
| 273 | 271 | ||
| 274 | TObject *luaH_set (lua_State *L, Hash *t, const TObject *key) { | 272 | void luaH_set (lua_State *L, Hash *t, const TObject *key, const TObject *val) { |
| 275 | const TObject *p = luaH_get(t, key); | 273 | const TObject *p = luaH_get(t, key); |
| 276 | if (p != &luaO_nilobject) return (TObject *)p; | 274 | if (p == &luaO_nilobject) { |
| 277 | else if (ttype(key) == LUA_TNIL) luaD_error(L, l_s("table index is nil")); | 275 | if (ttype(key) == LUA_TNIL) luaD_error(L, l_s("table index is nil")); |
| 278 | return newkey(L, t, key); | 276 | p = newkey(L, t, key); |
| 277 | } | ||
| 278 | settableval(p, val); | ||
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | 281 | ||
| 282 | TObject *luaH_setstr (lua_State *L, Hash *t, TString *key) { | 282 | void luaH_setstr (lua_State *L, Hash *t, TString *key, const TObject *val) { |
| 283 | const TObject *p = luaH_getstr(t, key); | 283 | const TObject *p = luaH_getstr(t, key); |
| 284 | if (p != &luaO_nilobject) return (TObject *)p; | 284 | if (p == &luaO_nilobject) { |
| 285 | else { | ||
| 286 | TObject k; | 285 | TObject k; |
| 287 | setsvalue(&k, key); | 286 | setsvalue(&k, key); |
| 288 | return newkey(L, t, &k); | 287 | p = newkey(L, t, &k); |
| 289 | } | 288 | } |
| 289 | settableval(p, val); | ||
| 290 | } | 290 | } |
| 291 | 291 | ||
| 292 | 292 | ||
| 293 | TObject *luaH_setnum (lua_State *L, Hash *t, int key) { | 293 | void luaH_setnum (lua_State *L, Hash *t, int key, const TObject *val) { |
| 294 | const TObject *p = luaH_getnum(t, key); | 294 | const TObject *p = luaH_getnum(t, key); |
| 295 | if (p != &luaO_nilobject) return (TObject *)p; | 295 | if (p == &luaO_nilobject) { |
| 296 | else { | ||
| 297 | TObject k; | 296 | TObject k; |
| 298 | setnvalue(&k, key); | 297 | setnvalue(&k, key); |
| 299 | return newkey(L, t, &k); | 298 | p = newkey(L, t, &k); |
| 300 | } | 299 | } |
| 300 | settableval(p, val); | ||
| 301 | } | 301 | } |
| 302 | 302 | ||
