aboutsummaryrefslogtreecommitdiff
path: root/ltable.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-02-20 12:27:53 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-02-20 12:27:53 -0200
commit81245b1ad51c5f4a4dd71da272b65b2450929b80 (patch)
tree25b69ceb42d06e1c3a32aabda7212b805f605349 /ltable.c
parent397ce11996bb1b5a6ef81fdf44252cf58b230937 (diff)
downloadlua-81245b1ad51c5f4a4dd71da272b65b2450929b80.tar.gz
lua-81245b1ad51c5f4a4dd71da272b65b2450929b80.tar.bz2
lua-81245b1ad51c5f4a4dd71da272b65b2450929b80.zip
'numisinteger' (for table keys) replaced by 'luaV_tointeger' (old
'tointeger_aux'), which can do the same job.
Diffstat (limited to 'ltable.c')
-rw-r--r--ltable.c22
1 files changed, 5 insertions, 17 deletions
diff --git a/ltable.c b/ltable.c
index 8d62ed60..5f4148eb 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 2.103 2015/02/16 13:15:00 roberto Exp roberto $ 2** $Id: ltable.c,v 2.104 2015/02/20 14:05:01 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*/
@@ -84,17 +84,6 @@ static const Node dummynode_ = {
84 84
85 85
86/* 86/*
87** Checks whether a float has a value representable as a lua_Integer
88** (and does the conversion if so)
89*/
90static int numisinteger (lua_Number x, lua_Integer *p) {
91 if ((x) == l_floor(x)) /* integral value? */
92 return lua_numbertointeger(x, p); /* try as an integer */
93 else return 0;
94}
95
96
97/*
98** Hash for floating-point numbers. 87** Hash for floating-point numbers.
99** The main computation should be just 88** The main computation should be just
100** n = frepx(n, &i); return (n * INT_MAX) + i 89** n = frepx(n, &i); return (n * INT_MAX) + i
@@ -455,14 +444,13 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
455 TValue aux; 444 TValue aux;
456 if (ttisnil(key)) luaG_runerror(L, "table index is nil"); 445 if (ttisnil(key)) luaG_runerror(L, "table index is nil");
457 else if (ttisfloat(key)) { 446 else if (ttisfloat(key)) {
458 lua_Number n = fltvalue(key);
459 lua_Integer k; 447 lua_Integer k;
460 if (luai_numisnan(n)) 448 if (luaV_tointeger(key, &k, 0)) { /* index is int? */
461 luaG_runerror(L, "table index is NaN");
462 if (numisinteger(n, &k)) { /* index is int? */
463 setivalue(&aux, k); 449 setivalue(&aux, k);
464 key = &aux; /* insert it as an integer */ 450 key = &aux; /* insert it as an integer */
465 } 451 }
452 else if (luai_numisnan(fltvalue(key)))
453 luaG_runerror(L, "table index is NaN");
466 } 454 }
467 mp = mainposition(t, key); 455 mp = mainposition(t, key);
468 if (!ttisnil(gval(mp)) || isdummy(mp)) { /* main position is taken? */ 456 if (!ttisnil(gval(mp)) || isdummy(mp)) { /* main position is taken? */
@@ -556,7 +544,7 @@ const TValue *luaH_get (Table *t, const TValue *key) {
556 case LUA_TNIL: return luaO_nilobject; 544 case LUA_TNIL: return luaO_nilobject;
557 case LUA_TNUMFLT: { 545 case LUA_TNUMFLT: {
558 lua_Integer k; 546 lua_Integer k;
559 if (numisinteger(fltvalue(key), &k)) /* index is int? */ 547 if (luaV_tointeger(key, &k, 0)) /* index is int? */
560 return luaH_getint(t, k); /* use specialized version */ 548 return luaH_getint(t, k); /* use specialized version */
561 /* else go through */ 549 /* else go through */
562 } 550 }