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;
}
template <typename Class>
usertype<Class> new_usertype(const std::string& name, optional<no_construction> no_default_constructor = nullopt) {
return global.new_usertype<Class>(name, std::move(no_default_constructor));
template <typename Class, typename... Args>
usertype<Class> new_usertype(const std::string& name, Args&&... args) {
return global.new_usertype<Class>(name, std::forward<Args>(args)...);
}
template <bool read_only = true, typename... Args>

View File

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

View File

@ -1208,7 +1208,10 @@ namespace sol {
struct is_constructor<filter_wrapper<F, Filters...>> : is_constructor<meta::unqualified_t<F>> {};
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>
struct is_destructor : std::false_type {};

View File

@ -147,7 +147,8 @@ namespace u_detail {
struct usertype_storage_base {
public:
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;
reference value_index_table;
reference reference_index_table;
@ -174,6 +175,13 @@ namespace u_detail {
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() {
storage.clear();
string_keys.clear();
@ -217,7 +225,7 @@ namespace u_detail {
if (k_type == type::string) {
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);
if (it != self.string_keys.cend()) {
target = &it->second;
@ -270,7 +278,7 @@ namespace u_detail {
if (k_type == type::string) {
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);
if (it != self.string_keys.cend()) {
target = &it->second;
@ -481,7 +489,7 @@ namespace u_detail {
this->base_new_index = ics;
}
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 {
// the reference-based implementation might compare poorly and hash
@ -506,8 +514,7 @@ namespace u_detail {
ics.binding_data = b.data();
ics.index = &b.index_call_with_<true, true>;
ics.new_index = &b.index_call_with_<false, true>;
this->string_keys.insert_or_assign(std::move(s), ics);
this->add_entry(s, std::move(ics));
}
else {
// its auxiliary and must be