aboutsummaryrefslogtreecommitdiff
path: root/ltable.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-01-06 11:38:31 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-01-06 11:38:31 -0300
commit5ff408d2189c6c24fdf8908db4a31432bbdd6f15 (patch)
treebcd83d7547dab0d5418116eb10f9c601f2f2d3b9 /ltable.c
parente3c83835e7b396ab7db538fb3b052f02d7807dee (diff)
downloadlua-5ff408d2189c6c24fdf8908db4a31432bbdd6f15.tar.gz
lua-5ff408d2189c6c24fdf8908db4a31432bbdd6f15.tar.bz2
lua-5ff408d2189c6c24fdf8908db4a31432bbdd6f15.zip
Changed internal representation of booleans
Instead of an explicit value (field 'b'), true and false use different tag variants. This avoids reading an extra field and results in more direct code. (Most code that uses booleans needs to distinguish between true and false anyway.)
Diffstat (limited to 'ltable.c')
-rw-r--r--ltable.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/ltable.c b/ltable.c
index cc3c3dd4..ebd45dda 100644
--- a/ltable.c
+++ b/ltable.c
@@ -143,8 +143,10 @@ static Node *mainposition (const Table *t, int ktt, const Value *kvl) {
143 return hashstr(t, tsvalueraw(*kvl)); 143 return hashstr(t, tsvalueraw(*kvl));
144 case LUA_TLNGSTR: 144 case LUA_TLNGSTR:
145 return hashpow2(t, luaS_hashlongstr(tsvalueraw(*kvl))); 145 return hashpow2(t, luaS_hashlongstr(tsvalueraw(*kvl)));
146 case LUA_TBOOLEAN: 146 case LUA_TFALSE:
147 return hashboolean(t, bvalueraw(*kvl)); 147 return hashboolean(t, 0);
148 case LUA_TTRUE:
149 return hashboolean(t, 1);
148 case LUA_TLIGHTUSERDATA: 150 case LUA_TLIGHTUSERDATA:
149 return hashpointer(t, pvalueraw(*kvl)); 151 return hashpointer(t, pvalueraw(*kvl));
150 case LUA_TLCF: 152 case LUA_TLCF:
@@ -175,14 +177,12 @@ static int equalkey (const TValue *k1, const Node *n2) {
175 if (rawtt(k1) != keytt(n2)) /* not the same variants? */ 177 if (rawtt(k1) != keytt(n2)) /* not the same variants? */
176 return 0; /* cannot be same key */ 178 return 0; /* cannot be same key */
177 switch (ttypetag(k1)) { 179 switch (ttypetag(k1)) {
178 case LUA_TNIL: 180 case LUA_TNIL: case LUA_TFALSE: case LUA_TTRUE:
179 return 1; 181 return 1;
180 case LUA_TNUMINT: 182 case LUA_TNUMINT:
181 return (ivalue(k1) == keyival(n2)); 183 return (ivalue(k1) == keyival(n2));
182 case LUA_TNUMFLT: 184 case LUA_TNUMFLT:
183 return luai_numeq(fltvalue(k1), fltvalueraw(keyval(n2))); 185 return luai_numeq(fltvalue(k1), fltvalueraw(keyval(n2)));
184 case LUA_TBOOLEAN:
185 return bvalue(k1) == bvalueraw(keyval(n2));
186 case LUA_TLIGHTUSERDATA: 186 case LUA_TLIGHTUSERDATA:
187 return pvalue(k1) == pvalueraw(keyval(n2)); 187 return pvalue(k1) == pvalueraw(keyval(n2));
188 case LUA_TLCF: 188 case LUA_TLCF: