diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-10-29 13:21:04 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-10-29 13:21:04 -0200 |
commit | c874abac98b4bbd73603c599bc8096ac800e1184 (patch) | |
tree | 322bdb95978ba3f9451d87ad330e4366c0b3ac52 | |
parent | 789e423b328b3483a11b0d85f92d4c5016388fa0 (diff) | |
download | lua-c874abac98b4bbd73603c599bc8096ac800e1184.tar.gz lua-c874abac98b4bbd73603c599bc8096ac800e1184.tar.bz2 lua-c874abac98b4bbd73603c599bc8096ac800e1184.zip |
with 'fast tracks', there is no need to do raw accesses in 'ipairs'
-rw-r--r-- | lbaselib.c | 25 |
1 files changed, 6 insertions, 19 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.310 2015/03/28 19:14:47 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.311 2015/06/26 19:25:45 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -86,8 +86,8 @@ static int luaB_tonumber (lua_State *L) { | |||
86 | const char *s; | 86 | const char *s; |
87 | lua_Integer n = 0; /* to avoid warnings */ | 87 | lua_Integer n = 0; /* to avoid warnings */ |
88 | lua_Integer base = luaL_checkinteger(L, 2); | 88 | lua_Integer base = luaL_checkinteger(L, 2); |
89 | luaL_checktype(L, 1, LUA_TSTRING); /* before 'luaL_checklstring'! */ | 89 | luaL_checktype(L, 1, LUA_TSTRING); /* no numbers as strings */ |
90 | s = luaL_checklstring(L, 1, &l); | 90 | s = lua_tolstring(L, 1, &l); |
91 | luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); | 91 | luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); |
92 | if (b_str2int(s, (int)base, &n) == s + l) { | 92 | if (b_str2int(s, (int)base, &n) == s + l) { |
93 | lua_pushinteger(L, n); | 93 | lua_pushinteger(L, n); |
@@ -241,18 +241,7 @@ static int luaB_pairs (lua_State *L) { | |||
241 | 241 | ||
242 | 242 | ||
243 | /* | 243 | /* |
244 | ** Traversal function for 'ipairs' for raw tables | 244 | ** Traversal function for 'ipairs' |
245 | */ | ||
246 | static int ipairsaux_raw (lua_State *L) { | ||
247 | lua_Integer i = luaL_checkinteger(L, 2) + 1; | ||
248 | luaL_checktype(L, 1, LUA_TTABLE); | ||
249 | lua_pushinteger(L, i); | ||
250 | return (lua_rawgeti(L, 1, i) == LUA_TNIL) ? 1 : 2; | ||
251 | } | ||
252 | |||
253 | |||
254 | /* | ||
255 | ** Traversal function for 'ipairs' for tables with metamethods | ||
256 | */ | 245 | */ |
257 | static int ipairsaux (lua_State *L) { | 246 | static int ipairsaux (lua_State *L) { |
258 | lua_Integer i = luaL_checkinteger(L, 2) + 1; | 247 | lua_Integer i = luaL_checkinteger(L, 2) + 1; |
@@ -267,13 +256,11 @@ static int ipairsaux (lua_State *L) { | |||
267 | ** that can affect the traversal. | 256 | ** that can affect the traversal. |
268 | */ | 257 | */ |
269 | static int luaB_ipairs (lua_State *L) { | 258 | static int luaB_ipairs (lua_State *L) { |
270 | lua_CFunction iter = (luaL_getmetafield(L, 1, "__index") != LUA_TNIL) | ||
271 | ? ipairsaux : ipairsaux_raw; | ||
272 | #if defined(LUA_COMPAT_IPAIRS) | 259 | #if defined(LUA_COMPAT_IPAIRS) |
273 | return pairsmeta(L, "__ipairs", 1, iter); | 260 | return pairsmeta(L, "__ipairs", 1, ipairsaux); |
274 | #else | 261 | #else |
275 | luaL_checkany(L, 1); | 262 | luaL_checkany(L, 1); |
276 | lua_pushcfunction(L, iter); /* iteration function */ | 263 | lua_pushcfunction(L, ipairsaux); /* iteration function */ |
277 | lua_pushvalue(L, 1); /* state */ | 264 | lua_pushvalue(L, 1); /* state */ |
278 | lua_pushinteger(L, 0); /* initial value */ | 265 | lua_pushinteger(L, 0); /* initial value */ |
279 | return 3; | 266 | return 3; |