Update Lua 5.4.4 rc1

This commit is contained in:
Cloud Wu
2021-11-17 10:57:20 +08:00
parent 38e5b1ca1c
commit d115e626e6
25 changed files with 440 additions and 216 deletions

View File

@@ -84,8 +84,6 @@
#define hashstr(t,str) hashpow2(t, (str)->hash)
#define hashboolean(t,p) hashpow2(t, p)
#define hashint(t,i) hashpow2(t, i)
#define hashpointer(t,p) hashmod(t, point2uint(p))
@@ -101,6 +99,20 @@ static const Node dummynode_ = {
static const TValue absentkey = {ABSTKEYCONSTANT};
/*
** Hash for integers. To allow a good hash, use the remainder operator
** ('%'). If integer fits as a non-negative int, compute an int
** remainder, which is faster. Otherwise, use an unsigned-integer
** remainder, which uses all bits and ensures a non-negative result.
*/
static Node *hashint (const Table *t, lua_Integer i) {
lua_Unsigned ui = l_castS2U(i);
if (ui <= (unsigned int)INT_MAX)
return hashmod(t, cast_int(ui));
else
return hashmod(t, ui);
}
/*
** Hash for floating-point numbers.
@@ -138,22 +150,22 @@ static int l_hashfloat (lua_Number n) {
** and value in 'vkl') so that we can call it on keys inserted into
** nodes.
*/
static Node *mainposition (const Table *t, int ktt, const Value *kvl) {
static Node *mainposition (const Table *t, int ktt, const Value kvl) {
switch (withvariant(ktt)) {
case LUA_VNUMINT: {
lua_Integer key = ivalueraw(*kvl);
lua_Integer key = ivalueraw(kvl);
return hashint(t, key);
}
case LUA_VNUMFLT: {
lua_Number n = fltvalueraw(*kvl);
lua_Number n = fltvalueraw(kvl);
return hashmod(t, l_hashfloat(n));
}
case LUA_VSHRSTR: {
TString *ts = tsvalueraw(*kvl);
TString *ts = tsvalueraw(kvl);
return hashstr(t, ts);
}
case LUA_VLNGSTR: {
TString *ts = tsvalueraw(*kvl);
TString *ts = tsvalueraw(kvl);
return hashpow2(t, luaS_hashlongstr(ts));
}
case LUA_VFALSE:
@@ -161,15 +173,15 @@ static Node *mainposition (const Table *t, int ktt, const Value *kvl) {
case LUA_VTRUE:
return hashboolean(t, 1);
case LUA_VLIGHTUSERDATA: {
void *p = pvalueraw(*kvl);
void *p = pvalueraw(kvl);
return hashpointer(t, p);
}
case LUA_VLCF: {
lua_CFunction f = fvalueraw(*kvl);
lua_CFunction f = fvalueraw(kvl);
return hashpointer(t, f);
}
default: {
GCObject *o = gcvalueraw(*kvl);
GCObject *o = gcvalueraw(kvl);
return hashpointer(t, o);
}
}
@@ -683,7 +695,7 @@ void luaH_newkey (lua_State *L, Table *t, const TValue *key, TValue *value) {
return;
}
lua_assert(!isdummy(t));
othern = mainposition(t, keytt(mp), &keyval(mp));
othern = mainposition(t, keytt(mp), keyval(mp));
if (othern != mp) { /* is colliding node out of its main position? */
/* yes; move colliding node into free position */
while (othern + gnext(othern) != mp) /* find previous */