commit 188192ce9a3d5d111d2c1ceed41d27ab6a5d57dc
parent fc083f1138c9e78b460445da03d9a37d42e9cd9d
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Wed, 29 May 2013 11:04:38 -0300
'luai_hashnum' "inlined" into 'hashfloat'
Diffstat:
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/ltable.c b/ltable.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltable.c,v 2.75 2013/04/29 17:12:50 roberto Exp roberto $
+** $Id: ltable.c,v 2.76 2013/05/27 12:43:37 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@@ -18,6 +18,8 @@
** Hence even when the load factor reaches 100%, performance remains good.
*/
+#include <float.h>
+#include <math.h>
#include <string.h>
#define ltable_c
@@ -82,11 +84,12 @@ static const Node dummynode_ = {
/*
-** hash for lua_Numbers
+** hash for floating-point numbers
*/
-static Node *hashnum (const Table *t, lua_Number n) {
+static Node *hashfloat (const Table *t, lua_Number n) {
int i;
- luai_hashnum(i, n);
+ n = l_mathop(frexp)(n, &i) * cast_num(INT_MAX - DBL_MAX_EXP);
+ i += cast_int(n);
if (i < 0) {
if (cast(unsigned int, i) == 0u - i) /* use unsigned to avoid overflows */
i = 0; /* handle INT_MIN */
@@ -106,7 +109,7 @@ static Node *mainposition (const Table *t, const TValue *key) {
case LUA_TNUMINT:
return hashint(t, ivalue(key));
case LUA_TNUMFLT:
- return hashnum(t, fltvalue(key));
+ return hashfloat(t, fltvalue(key));
case LUA_TSHRSTR:
return hashstr(t, rawtsvalue(key));
case LUA_TLNGSTR: {