aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-11-03 16:35:21 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-11-03 16:35:21 -0200
commit5100bc8aa1c05b1c967567c09d0c70b7c339cc28 (patch)
tree68c996b0c749133512ec9388551e97dfd5681195
parentebb2afa54bb038f6d7ddb81b908ffeb4a9c3dea3 (diff)
downloadlua-5100bc8aa1c05b1c967567c09d0c70b7c339cc28.tar.gz
lua-5100bc8aa1c05b1c967567c09d0c70b7c339cc28.tar.bz2
lua-5100bc8aa1c05b1c967567c09d0c70b7c339cc28.zip
no need for a special case to get long strings (not that common)
-rw-r--r--ltable.c38
1 files changed, 16 insertions, 22 deletions
diff --git a/ltable.c b/ltable.c
index 13d39dd3..ed57394e 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 2.114 2015/11/03 15:47:30 roberto Exp roberto $ 2** $Id: ltable.c,v 2.115 2015/11/03 18:10:44 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*/
@@ -508,7 +508,7 @@ const TValue *luaH_getint (Table *t, lua_Integer key) {
508 if (nx == 0) break; 508 if (nx == 0) break;
509 n += nx; 509 n += nx;
510 } 510 }
511 }; 511 }
512 return luaO_nilobject; 512 return luaO_nilobject;
513 } 513 }
514} 514}
@@ -534,11 +534,14 @@ const TValue *luaH_getshortstr (Table *t, TString *key) {
534} 534}
535 535
536 536
537static const TValue *getlngstr (Table *t, TString *key) { 537/*
538 Node *n = hashpow2(t, luaS_hashlongstr(key)); 538** "Generic" get version. (Not that generic: not valid for integers,
539** which may be in array part, nor for floats with integral values.)
540*/
541static const TValue *getgeneric (Table *t, const TValue *key) {
542 Node *n = mainposition(t, key);
539 for (;;) { /* check whether 'key' is somewhere in the chain */ 543 for (;;) { /* check whether 'key' is somewhere in the chain */
540 const TValue *k = gkey(n); 544 if (luaV_rawequalobj(gkey(n), key))
541 if (ttislngstring(k) && luaS_eqlngstr(tsvalue(k), key))
542 return gval(n); /* that's it */ 545 return gval(n); /* that's it */
543 else { 546 else {
544 int nx = gnext(n); 547 int nx = gnext(n);
@@ -553,8 +556,11 @@ static const TValue *getlngstr (Table *t, TString *key) {
553const TValue *luaH_getstr (Table *t, TString *key) { 556const TValue *luaH_getstr (Table *t, TString *key) {
554 if (key->tt == LUA_TSHRSTR) 557 if (key->tt == LUA_TSHRSTR)
555 return luaH_getshortstr(t, key); 558 return luaH_getshortstr(t, key);
556 else 559 else { /* for long strings, use generic case */
557 return getlngstr(t, key); 560 TValue ko;
561 setsvalue(cast(lua_State *, NULL), &ko, key);
562 return getgeneric(t, &ko);
563 }
558} 564}
559 565
560 566
@@ -564,7 +570,6 @@ const TValue *luaH_getstr (Table *t, TString *key) {
564const TValue *luaH_get (Table *t, const TValue *key) { 570const TValue *luaH_get (Table *t, const TValue *key) {
565 switch (ttype(key)) { 571 switch (ttype(key)) {
566 case LUA_TSHRSTR: return luaH_getshortstr(t, tsvalue(key)); 572 case LUA_TSHRSTR: return luaH_getshortstr(t, tsvalue(key));
567 case LUA_TLNGSTR: return getlngstr(t, tsvalue(key));
568 case LUA_TNUMINT: return luaH_getint(t, ivalue(key)); 573 case LUA_TNUMINT: return luaH_getint(t, ivalue(key));
569 case LUA_TNIL: return luaO_nilobject; 574 case LUA_TNIL: return luaO_nilobject;
570 case LUA_TNUMFLT: { 575 case LUA_TNUMFLT: {
@@ -573,19 +578,8 @@ const TValue *luaH_get (Table *t, const TValue *key) {
573 return luaH_getint(t, k); /* use specialized version */ 578 return luaH_getint(t, k); /* use specialized version */
574 /* else... */ 579 /* else... */
575 } /* FALLTHROUGH */ 580 } /* FALLTHROUGH */
576 default: { 581 default:
577 Node *n = mainposition(t, key); 582 return getgeneric(t, key);
578 for (;;) { /* check whether 'key' is somewhere in the chain */
579 if (luaV_rawequalobj(gkey(n), key))
580 return gval(n); /* that's it */
581 else {
582 int nx = gnext(n);
583 if (nx == 0)
584 return luaO_nilobject; /* not found */
585 n += nx;
586 }
587 };
588 }
589 } 583 }
590} 584}
591 585