mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Add hinting optimization to arrays
This commit is contained in:
parent
1ae78e1b54
commit
e31ed71006
2
Optional
2
Optional
|
@ -1 +1 @@
|
||||||
Subproject commit c386acbdf2d6ae368de7cba55801b06d362bdaac
|
Subproject commit 45112c085a4ca75b5591dde3bf46faf4969c3026
|
|
@ -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-19 03:51:21.744027 UTC
|
// Generated 2016-08-20 01:06:43.957511 UTC
|
||||||
// This header was generated with sol v2.11.4 (revision c8ea9f7)
|
// This header was generated with sol v2.11.4 (revision 1ae78e1)
|
||||||
// https://github.com/ThePhD/sol2
|
// https://github.com/ThePhD/sol2
|
||||||
|
|
||||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||||
|
@ -736,8 +736,6 @@ namespace sol {
|
||||||
|
|
||||||
// beginning of sol/optional.hpp
|
// beginning of sol/optional.hpp
|
||||||
|
|
||||||
#if defined(SOL_USE_BOOST)
|
|
||||||
#include <boost/optional.hpp>
|
|
||||||
// beginning of sol/in_place.hpp
|
// beginning of sol/in_place.hpp
|
||||||
|
|
||||||
namespace sol {
|
namespace sol {
|
||||||
|
@ -767,6 +765,8 @@ namespace sol {
|
||||||
|
|
||||||
// end of sol/in_place.hpp
|
// end of sol/in_place.hpp
|
||||||
|
|
||||||
|
#if defined(SOL_USE_BOOST)
|
||||||
|
#include <boost/optional.hpp>
|
||||||
#else
|
#else
|
||||||
// beginning of Optional/optional.hpp
|
// beginning of Optional/optional.hpp
|
||||||
|
|
||||||
|
@ -3837,6 +3837,8 @@ namespace sol {
|
||||||
|
|
||||||
// end of sol/tie.hpp
|
// end of sol/tie.hpp
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace sol {
|
namespace sol {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
struct as_reference_tag {};
|
struct as_reference_tag {};
|
||||||
|
@ -3859,6 +3861,19 @@ namespace sol {
|
||||||
(dx)(memory);
|
(dx)(memory);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void reserve(T&, std::size_t) {}
|
||||||
|
|
||||||
|
template <typename T, typename Al>
|
||||||
|
void reserve(std::vector<T, Al>& arr, std::size_t hint) {
|
||||||
|
arr.reserve(hint);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename Tr, typename Al>
|
||||||
|
void reserve(std::basic_string<T, Tr, Al>& arr, std::size_t hint) {
|
||||||
|
arr.reserve(hint);
|
||||||
|
}
|
||||||
} // detail
|
} // detail
|
||||||
|
|
||||||
namespace stack {
|
namespace stack {
|
||||||
|
@ -4842,8 +4857,13 @@ namespace sol {
|
||||||
typedef typename T::value_type V;
|
typedef typename T::value_type V;
|
||||||
tracking.use(1);
|
tracking.use(1);
|
||||||
|
|
||||||
T arr;
|
|
||||||
index = lua_absindex(L, index);
|
index = lua_absindex(L, index);
|
||||||
|
T arr;
|
||||||
|
get_field<false, true>(L, static_cast<lua_Integer>(-1), index);
|
||||||
|
optional<std::size_t> sizehint = pop<optional<std::size_t>>(L);
|
||||||
|
if (sizehint) {
|
||||||
|
detail::reserve(arr, *sizehint);
|
||||||
|
}
|
||||||
#if SOL_LUA_VERSION >= 503
|
#if SOL_LUA_VERSION >= 503
|
||||||
// This method is HIGHLY performant over regular table iteration thanks to the Lua API changes in 5.3
|
// 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)) {
|
for (lua_Integer i = 0; ; ++i, lua_pop(L, 1)) {
|
||||||
|
@ -5606,6 +5626,7 @@ namespace sol {
|
||||||
for (auto&& i : cont) {
|
for (auto&& i : cont) {
|
||||||
set_field(L, index++, i, tableindex);
|
set_field(L, index++, i, tableindex);
|
||||||
}
|
}
|
||||||
|
set_field(L, -1, cont.size());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -9701,8 +9722,6 @@ namespace sol {
|
||||||
|
|
||||||
// beginning of sol/simple_usertype_metatable.hpp
|
// beginning of sol/simple_usertype_metatable.hpp
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace sol {
|
namespace sol {
|
||||||
|
|
||||||
struct simple_tag {} const simple{};
|
struct simple_tag {} const simple{};
|
||||||
|
|
|
@ -22,9 +22,9 @@
|
||||||
#ifndef SOL_OPTIONAL_HPP
|
#ifndef SOL_OPTIONAL_HPP
|
||||||
#define SOL_OPTIONAL_HPP
|
#define SOL_OPTIONAL_HPP
|
||||||
|
|
||||||
|
#include "in_place.hpp"
|
||||||
#if defined(SOL_USE_BOOST)
|
#if defined(SOL_USE_BOOST)
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
#include "../sol/in_place.hpp"
|
|
||||||
#else
|
#else
|
||||||
#include "../Optional/optional.hpp"
|
#include "../Optional/optional.hpp"
|
||||||
#endif // Boost vs. Better optional
|
#endif // Boost vs. Better optional
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include "tuple.hpp"
|
#include "tuple.hpp"
|
||||||
#include "traits.hpp"
|
#include "traits.hpp"
|
||||||
#include "tie.hpp"
|
#include "tie.hpp"
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace sol {
|
namespace sol {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
@ -52,6 +54,19 @@ namespace sol {
|
||||||
(dx)(memory);
|
(dx)(memory);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void reserve(T&, std::size_t) {}
|
||||||
|
|
||||||
|
template <typename T, typename Al>
|
||||||
|
void reserve(std::vector<T, Al>& arr, std::size_t hint) {
|
||||||
|
arr.reserve(hint);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename Tr, typename Al>
|
||||||
|
void reserve(std::basic_string<T, Tr, Al>& arr, std::size_t hint) {
|
||||||
|
arr.reserve(hint);
|
||||||
|
}
|
||||||
} // detail
|
} // detail
|
||||||
|
|
||||||
namespace stack {
|
namespace stack {
|
||||||
|
|
|
@ -83,8 +83,14 @@ namespace sol {
|
||||||
typedef typename T::value_type V;
|
typedef typename T::value_type V;
|
||||||
tracking.use(1);
|
tracking.use(1);
|
||||||
|
|
||||||
T arr;
|
|
||||||
index = lua_absindex(L, index);
|
index = lua_absindex(L, index);
|
||||||
|
T arr;
|
||||||
|
get_field<false, true>(L, static_cast<lua_Integer>(-1), index);
|
||||||
|
optional<std::size_t> sizehint = pop<optional<std::size_t>>(L);
|
||||||
|
if (sizehint) {
|
||||||
|
detail::reserve(arr, *sizehint);
|
||||||
|
}
|
||||||
#if SOL_LUA_VERSION >= 503
|
#if SOL_LUA_VERSION >= 503
|
||||||
// This method is HIGHLY performant over regular table iteration thanks to the Lua API changes in 5.3
|
// 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)) {
|
for (lua_Integer i = 0; ; ++i, lua_pop(L, 1)) {
|
||||||
|
|
|
@ -168,6 +168,7 @@ namespace sol {
|
||||||
for (auto&& i : cont) {
|
for (auto&& i : cont) {
|
||||||
set_field(L, index++, i, tableindex);
|
set_field(L, index++, i, tableindex);
|
||||||
}
|
}
|
||||||
|
set_field(L, -1, cont.size());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user