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.
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// This file was generated with a script.
|
// This file was generated with a script.
|
||||||
// Generated 2016-08-17 20:02:13.087012 UTC
|
// Generated 2016-08-19 03:51:21.744027 UTC
|
||||||
// This header was generated with sol v2.11.4 (revision 5ac32c7)
|
// This header was generated with sol v2.11.4 (revision c8ea9f7)
|
||||||
// https://github.com/ThePhD/sol2
|
// https://github.com/ThePhD/sol2
|
||||||
|
|
||||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||||
@ -4844,17 +4844,35 @@ namespace sol {
|
|||||||
|
|
||||||
T arr;
|
T arr;
|
||||||
index = lua_absindex(L, index);
|
index = lua_absindex(L, index);
|
||||||
lua_pushnil(L);
|
#if SOL_LUA_VERSION >= 503
|
||||||
while (lua_next(L, index) != 0) {
|
// This method is HIGHLY performant over regular table iteration thanks to the Lua API changes in 5.3
|
||||||
int isint = 0;
|
for (lua_Integer i = 0; ; ++i, lua_pop(L, 1)) {
|
||||||
lua_tointegerx(L, -2, &isint);
|
type t = static_cast<type>(lua_geti(L, index, i));
|
||||||
if (isint == 0) {
|
if (t == type::nil) {
|
||||||
lua_pop(L, 1);
|
if (i == 0)
|
||||||
continue;
|
continue;
|
||||||
|
else
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
arr.push_back(stack::get<V>(L, -1));
|
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;
|
return arr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -85,17 +85,35 @@ namespace sol {
|
|||||||
|
|
||||||
T arr;
|
T arr;
|
||||||
index = lua_absindex(L, index);
|
index = lua_absindex(L, index);
|
||||||
lua_pushnil(L);
|
#if SOL_LUA_VERSION >= 503
|
||||||
while (lua_next(L, index) != 0) {
|
// This method is HIGHLY performant over regular table iteration thanks to the Lua API changes in 5.3
|
||||||
int isint = 0;
|
for (lua_Integer i = 0; ; ++i, lua_pop(L, 1)) {
|
||||||
lua_tointegerx(L, -2, &isint);
|
type t = static_cast<type>(lua_geti(L, index, i));
|
||||||
if (isint == 0) {
|
if (t == type::nil) {
|
||||||
lua_pop(L, 1);
|
if (i == 0)
|
||||||
continue;
|
continue;
|
||||||
|
else
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
arr.push_back(stack::get<V>(L, -1));
|
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;
|
return arr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user