freeze and test

This commit is contained in:
ThePhD 2018-11-11 13:40:28 -08:00
parent 593dfc08ef
commit e74ce68163
No known key found for this signature in database
GPG Key ID: 1509DB1C0F702BFA
4 changed files with 24 additions and 13 deletions

View File

@ -652,9 +652,9 @@ namespace sol {
return *this; return *this;
} }
template <typename Class> template <typename Class, typename... Args>
usertype<Class> new_usertype(const std::string& name, optional<no_construction> no_default_constructor = nullopt) { usertype<Class> new_usertype(const std::string& name, Args&&... args) {
return global.new_usertype<Class>(name, std::move(no_default_constructor)); return global.new_usertype<Class>(name, std::forward<Args>(args)...);
} }
template <bool read_only = true, typename... Args> template <bool read_only = true, typename... Args>

View File

@ -31,10 +31,11 @@ namespace sol {
typedef table_core<false> table; typedef table_core<false> table;
template <bool top_level, typename base_type> template <bool top_level, typename base_type>
template <typename Class, typename Key> template <typename Class, typename Key, typename... Args>
usertype<Class> basic_table_core<top_level, base_type>::new_usertype(Key&& key, optional<no_construction> no_default_constructor /* = nullopt*/) { usertype<Class> basic_table_core<top_level, base_type>::new_usertype(Key&& key, Args&&... args) {
int mt_index = u_detail::register_usertype<Class>(this->lua_state(), std::move(no_default_constructor)); int mt_index = u_detail::register_usertype<Class>(this->lua_state(), detail::any_is_constructor_v<Args...> ? optional<no_construction>() : optional<no_construction>(no_constructor));
usertype<Class> mt(this->lua_state(), -mt_index); usertype<Class> mt(this->lua_state(), -mt_index);
mt.
set(std::forward<Key>(key), mt); set(std::forward<Key>(key), mt);
return mt; return mt;
} }

View File

@ -1208,7 +1208,10 @@ namespace sol {
struct is_constructor<filter_wrapper<F, Filters...>> : is_constructor<meta::unqualified_t<F>> {}; struct is_constructor<filter_wrapper<F, Filters...>> : is_constructor<meta::unqualified_t<F>> {};
template <typename... Args> template <typename... Args>
using has_constructor = meta::any<is_constructor<meta::unqualified_t<Args>>...>; using any_is_constructor = meta::any<is_constructor<meta::unqualified_t<Args>>...>;
template <typename... Args>
using any_is_constructor_v = any_is_constructor<Args...>::value;
template <typename T> template <typename T>
struct is_destructor : std::false_type {}; struct is_destructor : std::false_type {};

View File

@ -147,7 +147,8 @@ namespace u_detail {
struct usertype_storage_base { struct usertype_storage_base {
public: public:
std::vector<std::unique_ptr<binding_base>> storage; std::vector<std::unique_ptr<binding_base>> storage;
detail::unordered_map<std::string, index_call_storage> string_keys; std::vector<std::vector<char>> string_keys_storage;
detail::unordered_map<string_view, index_call_storage> string_keys;
detail::unordered_map<reference, reference, reference_hash, reference_equals> auxiliary_keys; detail::unordered_map<reference, reference, reference_hash, reference_equals> auxiliary_keys;
reference value_index_table; reference value_index_table;
reference reference_index_table; reference reference_index_table;
@ -174,6 +175,13 @@ namespace u_detail {
base_new_index.new_index = new_index_target_fail; base_new_index.new_index = new_index_target_fail;
} }
void add_entry(string_view sv, index_call_storage ics) {
string_keys_storage.emplace_back(sv.begin(), sv.end());
std::vector<char>& sv_storage = string_keys_storage.back();
string_view stored_sv(sv_storage.data(), sv_storage.size());
string_keys.insert_or_assign(std::move(stored_sv), std::move(ics));
}
void clear() { void clear() {
storage.clear(); storage.clear();
string_keys.clear(); string_keys.clear();
@ -217,7 +225,7 @@ namespace u_detail {
if (k_type == type::string) { if (k_type == type::string) {
index_call_storage* target = nullptr; index_call_storage* target = nullptr;
{ {
std::string k = stack::get<std::string>(L, 2); string_view k = stack::get<string_view>(L, 2);
auto it = self.string_keys.find(k); auto it = self.string_keys.find(k);
if (it != self.string_keys.cend()) { if (it != self.string_keys.cend()) {
target = &it->second; target = &it->second;
@ -270,7 +278,7 @@ namespace u_detail {
if (k_type == type::string) { if (k_type == type::string) {
index_call_storage* target = nullptr; index_call_storage* target = nullptr;
{ {
std::string k = stack::get<std::string>(L, 2); string_view k = stack::get<string_view>(L, 2);
auto it = self.string_keys.find(k); auto it = self.string_keys.find(k);
if (it != self.string_keys.cend()) { if (it != self.string_keys.cend()) {
target = &it->second; target = &it->second;
@ -481,7 +489,7 @@ namespace u_detail {
this->base_new_index = ics; this->base_new_index = ics;
} }
this->for_each_table(L, fet); this->for_each_table(L, fet);
this->string_keys.insert_or_assign(std::move(s), std::move(ics)); this->add_entry(s, std::move(ics));
} }
else { else {
// the reference-based implementation might compare poorly and hash // the reference-based implementation might compare poorly and hash
@ -506,8 +514,7 @@ namespace u_detail {
ics.binding_data = b.data(); ics.binding_data = b.data();
ics.index = &b.index_call_with_<true, true>; ics.index = &b.index_call_with_<true, true>;
ics.new_index = &b.index_call_with_<false, true>; ics.new_index = &b.index_call_with_<false, true>;
this->add_entry(s, std::move(ics));
this->string_keys.insert_or_assign(std::move(s), ics);
} }
else { else {
// its auxiliary and must be // its auxiliary and must be