summaryrefslogtreecommitdiff
path: root/ltable.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-10-23 10:31:12 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-10-23 10:31:12 -0200
commitf6ed285cf2916765d7291af19a11292f4bb8689c (patch)
tree09579b472c9bd8ba5c8b08bf6dc8ffbfc97db89c /ltable.c
parent1448e736f08e65758fd0caa0f06a3723eb1585c3 (diff)
downloadlua-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.c15
1 files changed, 7 insertions, 8 deletions
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 <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);
}