diff options
Diffstat (limited to 'ltable.c')
| -rw-r--r-- | ltable.c | 21 |
1 files changed, 15 insertions, 6 deletions
| @@ -50,7 +50,7 @@ | |||
| 50 | 50 | ||
| 51 | #define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t)))) | 51 | #define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t)))) |
| 52 | 52 | ||
| 53 | #define hashstr(t,str) hashpow2(t, (str)->tsv.hash) | 53 | #define hashstr(t,str) hashpow2(t, (str)->tsv.hash) |
| 54 | #define hashboolean(t,p) hashpow2(t, p) | 54 | #define hashboolean(t,p) hashpow2(t, p) |
| 55 | 55 | ||
| 56 | 56 | ||
| @@ -98,7 +98,15 @@ static Node *mainposition (const Table *t, const TValue *key) { | |||
| 98 | switch (ttype(key)) { | 98 | switch (ttype(key)) { |
| 99 | case LUA_TNUMBER: | 99 | case LUA_TNUMBER: |
| 100 | return hashnum(t, nvalue(key)); | 100 | return hashnum(t, nvalue(key)); |
| 101 | case LUA_TSTRING: | 101 | case LUA_TLNGSTR: { |
| 102 | TString *s = rawtsvalue(key); | ||
| 103 | if (s->tsv.extra == 0) { /* no hash? */ | ||
| 104 | s->tsv.hash = luaS_hash(getstr(s), s->tsv.len); | ||
| 105 | s->tsv.extra = 1; /* now it has its hash */ | ||
| 106 | } | ||
| 107 | return hashstr(t, rawtsvalue(key)); | ||
| 108 | } | ||
| 109 | case LUA_TSHRSTR: | ||
| 102 | return hashstr(t, rawtsvalue(key)); | 110 | return hashstr(t, rawtsvalue(key)); |
| 103 | case LUA_TBOOLEAN: | 111 | case LUA_TBOOLEAN: |
| 104 | return hashboolean(t, bvalue(key)); | 112 | return hashboolean(t, bvalue(key)); |
| @@ -453,12 +461,13 @@ const TValue *luaH_getint (Table *t, int key) { | |||
| 453 | 461 | ||
| 454 | 462 | ||
| 455 | /* | 463 | /* |
| 456 | ** search function for strings | 464 | ** search function for short strings |
| 457 | */ | 465 | */ |
| 458 | const TValue *luaH_getstr (Table *t, TString *key) { | 466 | const TValue *luaH_getstr (Table *t, TString *key) { |
| 459 | Node *n = hashstr(t, key); | 467 | Node *n = hashstr(t, key); |
| 468 | lua_assert(key->tsv.tt == LUA_TSHRSTR); | ||
| 460 | do { /* check whether `key' is somewhere in the chain */ | 469 | do { /* check whether `key' is somewhere in the chain */ |
| 461 | if (ttisstring(gkey(n)) && luaS_eqstr(rawtsvalue(gkey(n)), key)) | 470 | if (ttisshrstring(gkey(n)) && eqshrstr(rawtsvalue(gkey(n)), key)) |
| 462 | return gval(n); /* that's it */ | 471 | return gval(n); /* that's it */ |
| 463 | else n = gnext(n); | 472 | else n = gnext(n); |
| 464 | } while (n); | 473 | } while (n); |
| @@ -470,9 +479,9 @@ const TValue *luaH_getstr (Table *t, TString *key) { | |||
| 470 | ** main search function | 479 | ** main search function |
| 471 | */ | 480 | */ |
| 472 | const TValue *luaH_get (Table *t, const TValue *key) { | 481 | const TValue *luaH_get (Table *t, const TValue *key) { |
| 473 | switch (ttypenv(key)) { | 482 | switch (ttype(key)) { |
| 474 | case LUA_TNIL: return luaO_nilobject; | 483 | case LUA_TNIL: return luaO_nilobject; |
| 475 | case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key)); | 484 | case LUA_TSHRSTR: return luaH_getstr(t, rawtsvalue(key)); |
| 476 | case LUA_TNUMBER: { | 485 | case LUA_TNUMBER: { |
| 477 | int k; | 486 | int k; |
| 478 | lua_Number n = nvalue(key); | 487 | lua_Number n = nvalue(key); |
