From f6ed285cf2916765d7291af19a11292f4bb8689c Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 23 Oct 2009 10:31:12 -0200 Subject: new hash for doubles based on frexp, to avoid low-level tricks --- ltable.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'ltable.c') diff --git a/ltable.c b/ltable.c index 1c2b2b6f..826dd194 100644 --- a/ltable.c +++ b/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 2.40 2009/04/17 14:40:13 roberto Exp roberto $ +** $Id: ltable.c,v 2.41 2009/08/07 17:53:28 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -18,7 +18,6 @@ ** Hence even when the load factor reaches 100%, performance remains good. */ -#include #include #define ltable_c @@ -82,13 +81,13 @@ static const Node dummynode_ = { ** hash for lua_Numbers */ static Node *hashnum (const Table *t, lua_Number n) { - unsigned int a[numints]; int i; - if (luai_numeq(n, 0)) /* avoid problems with -0 */ - return gnode(t, 0); - memcpy(a, &n, sizeof(a)); - for (i = 1; i < numints; i++) a[0] += a[i]; - return hashmod(t, a[0]); + luai_hashnum(i, n); + if (i < 0) { + i = -i; /* must be a positive value */ + if (i < 0) i = 0; /* handle INT_MIN */ + } + return hashmod(t, i); } -- cgit v1.2.3-55-g6feb