diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-02-20 12:27:53 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-02-20 12:27:53 -0200 |
commit | 81245b1ad51c5f4a4dd71da272b65b2450929b80 (patch) | |
tree | 25b69ceb42d06e1c3a32aabda7212b805f605349 /ltable.c | |
parent | 397ce11996bb1b5a6ef81fdf44252cf58b230937 (diff) | |
download | lua-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.c | 22 |
1 files changed, 5 insertions, 17 deletions
@@ -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 | */ | ||
90 | static 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 | } |