diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-10-23 10:31:12 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-10-23 10:31:12 -0200 |
commit | f6ed285cf2916765d7291af19a11292f4bb8689c (patch) | |
tree | 09579b472c9bd8ba5c8b08bf6dc8ffbfc97db89c /ltable.c | |
parent | 1448e736f08e65758fd0caa0f06a3723eb1585c3 (diff) | |
download | lua-github-f6ed285cf2916765d7291af19a11292f4bb8689c.tar.gz |
new hash for doubles based on frexp, to avoid low-level tricks
Diffstat (limited to 'ltable.c')
-rw-r--r-- | ltable.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -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 <math.h> #include <string.h> #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); } |