mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
High performance iteration for arrays
This commit is contained in:
parent
c8ea9f7638
commit
1ae78e1b54
|
@ -20,8 +20,8 @@
|
|||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// This file was generated with a script.
|
||||
// Generated 2016-08-17 20:02:13.087012 UTC
|
||||
// This header was generated with sol v2.11.4 (revision 5ac32c7)
|
||||
// Generated 2016-08-19 03:51:21.744027 UTC
|
||||
// This header was generated with sol v2.11.4 (revision c8ea9f7)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||
|
@ -4844,17 +4844,35 @@ namespace sol {
|
|||
|
||||
T arr;
|
||||
index = lua_absindex(L, index);
|
||||
lua_pushnil(L);
|
||||
while (lua_next(L, index) != 0) {
|
||||
int isint = 0;
|
||||
lua_tointegerx(L, -2, &isint);
|
||||
if (isint == 0) {
|
||||
lua_pop(L, 1);
|
||||
continue;
|
||||
#if SOL_LUA_VERSION >= 503
|
||||
// This method is HIGHLY performant over regular table iteration thanks to the Lua API changes in 5.3
|
||||
for (lua_Integer i = 0; ; ++i, lua_pop(L, 1)) {
|
||||
type t = static_cast<type>(lua_geti(L, index, i));
|
||||
if (t == type::nil) {
|
||||
if (i == 0)
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
arr.push_back(stack::get<V>(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
#else
|
||||
// Zzzz slower but necessary thanks to the lower version API and missing functions qq
|
||||
for (lua_Integer i = 0; ; ++i, lua_pop(L, 1)) {
|
||||
lua_pushinteger(L, i);
|
||||
lua_gettable(L, index);
|
||||
type t = type_of(L, -1);
|
||||
if (t == type::nil) {
|
||||
if (i == 0)
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
arr.push_back(stack::get<V>(L, -1));
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
#endif
|
||||
return arr;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -85,17 +85,35 @@ namespace sol {
|
|||
|
||||
T arr;
|
||||
index = lua_absindex(L, index);
|
||||
lua_pushnil(L);
|
||||
while (lua_next(L, index) != 0) {
|
||||
int isint = 0;
|
||||
lua_tointegerx(L, -2, &isint);
|
||||
if (isint == 0) {
|
||||
lua_pop(L, 1);
|
||||
continue;
|
||||
#if SOL_LUA_VERSION >= 503
|
||||
// This method is HIGHLY performant over regular table iteration thanks to the Lua API changes in 5.3
|
||||
for (lua_Integer i = 0; ; ++i, lua_pop(L, 1)) {
|
||||
type t = static_cast<type>(lua_geti(L, index, i));
|
||||
if (t == type::nil) {
|
||||
if (i == 0)
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
arr.push_back(stack::get<V>(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
#else
|
||||
// Zzzz slower but necessary thanks to the lower version API and missing functions qq
|
||||
for (lua_Integer i = 0; ; ++i, lua_pop(L, 1)) {
|
||||
lua_pushinteger(L, i);
|
||||
lua_gettable(L, index);
|
||||
type t = type_of(L, -1);
|
||||
if (t == type::nil) {
|
||||
if (i == 0)
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
arr.push_back(stack::get<V>(L, -1));
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
#endif
|
||||
return arr;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user