aboutsummaryrefslogtreecommitdiff
path: root/ltable.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2012-01-25 19:05:40 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2012-01-25 19:05:40 -0200
commita4b96ce9a3305ae3585c0bb143fa7342c140f20b (patch)
treefbb635282c4b72dde25e5c9ffb2bc6d314419d05 /ltable.c
parent291f564485d8968fc7b0d043dda5ff91a7ce604b (diff)
downloadlua-a4b96ce9a3305ae3585c0bb143fa7342c140f20b.tar.gz
lua-a4b96ce9a3305ae3585c0bb143fa7342c140f20b.tar.bz2
lua-a4b96ce9a3305ae3585c0bb143fa7342c140f20b.zip
first implementation of long strings
Diffstat (limited to 'ltable.c')
-rw-r--r--ltable.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/ltable.c b/ltable.c
index ce740ebe..3683fe60 100644
--- a/ltable.c
+++ b/ltable.c
@@ -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*/
458const TValue *luaH_getstr (Table *t, TString *key) { 466const 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*/
472const TValue *luaH_get (Table *t, const TValue *key) { 481const 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);