aboutsummaryrefslogtreecommitdiff
path: root/ltable.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-05-29 11:05:03 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-05-29 11:05:03 -0300
commit188192ce9a3d5d111d2c1ceed41d27ab6a5d57dc (patch)
tree193bb1f15398302ffcaf803fa33f0bb88106913f /ltable.c
parentfc083f1138c9e78b460445da03d9a37d42e9cd9d (diff)
downloadlua-188192ce9a3d5d111d2c1ceed41d27ab6a5d57dc.tar.gz
lua-188192ce9a3d5d111d2c1ceed41d27ab6a5d57dc.tar.bz2
lua-188192ce9a3d5d111d2c1ceed41d27ab6a5d57dc.zip
'luai_hashnum' "inlined" into 'hashfloat'
Diffstat (limited to 'ltable.c')
-rw-r--r--ltable.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/ltable.c b/ltable.c
index ae92cbd9..80d3ff3e 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 2.75 2013/04/29 17:12:50 roberto Exp roberto $ 2** $Id: ltable.c,v 2.76 2013/05/27 12:43:37 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -18,6 +18,8 @@
18** Hence even when the load factor reaches 100%, performance remains good. 18** Hence even when the load factor reaches 100%, performance remains good.
19*/ 19*/
20 20
21#include <float.h>
22#include <math.h>
21#include <string.h> 23#include <string.h>
22 24
23#define ltable_c 25#define ltable_c
@@ -82,11 +84,12 @@ static const Node dummynode_ = {
82 84
83 85
84/* 86/*
85** hash for lua_Numbers 87** hash for floating-point numbers
86*/ 88*/
87static Node *hashnum (const Table *t, lua_Number n) { 89static Node *hashfloat (const Table *t, lua_Number n) {
88 int i; 90 int i;
89 luai_hashnum(i, n); 91 n = l_mathop(frexp)(n, &i) * cast_num(INT_MAX - DBL_MAX_EXP);
92 i += cast_int(n);
90 if (i < 0) { 93 if (i < 0) {
91 if (cast(unsigned int, i) == 0u - i) /* use unsigned to avoid overflows */ 94 if (cast(unsigned int, i) == 0u - i) /* use unsigned to avoid overflows */
92 i = 0; /* handle INT_MIN */ 95 i = 0; /* handle INT_MIN */
@@ -106,7 +109,7 @@ static Node *mainposition (const Table *t, const TValue *key) {
106 case LUA_TNUMINT: 109 case LUA_TNUMINT:
107 return hashint(t, ivalue(key)); 110 return hashint(t, ivalue(key));
108 case LUA_TNUMFLT: 111 case LUA_TNUMFLT:
109 return hashnum(t, fltvalue(key)); 112 return hashfloat(t, fltvalue(key));
110 case LUA_TSHRSTR: 113 case LUA_TSHRSTR:
111 return hashstr(t, rawtsvalue(key)); 114 return hashstr(t, rawtsvalue(key));
112 case LUA_TLNGSTR: { 115 case LUA_TLNGSTR: {