Use std::bitset instead std::array of bool

This commit is contained in:
Ilya Averyanov 2018-01-22 16:36:36 +03:00 committed by The Phantom Derpstorm
parent f5764337cb
commit 6ae78d9ed8

View File

@ -40,6 +40,7 @@
#include <cstdio> #include <cstdio>
#include <sstream> #include <sstream>
#include <cassert> #include <cassert>
#include <bitset>
namespace sol { namespace sol {
namespace usertype_detail { namespace usertype_detail {
@ -399,7 +400,7 @@ namespace sol {
void* baseclasscheck; void* baseclasscheck;
void* baseclasscast; void* baseclasscast;
bool secondarymeta; bool secondarymeta;
std::array<bool, 32> properties; std::bitset<32> properties;
template <std::size_t Idx, meta::enable<std::is_same<lua_CFunction, meta::unqualified_tuple_element<Idx + 1, RawTuple>>> = meta::enabler> template <std::size_t Idx, meta::enable<std::is_same<lua_CFunction, meta::unqualified_tuple_element<Idx + 1, RawTuple>>> = meta::enabler>
lua_CFunction make_func() const { lua_CFunction make_func() const {
@ -464,12 +465,11 @@ namespace sol {
luaL_Reg reg = usertype_detail::make_reg(std::forward<N>(n), make_func<Idx>()); luaL_Reg reg = usertype_detail::make_reg(std::forward<N>(n), make_func<Idx>());
for (std::size_t i = 0; i < properties.size(); ++i) { for (std::size_t i = 0; i < properties.size(); ++i) {
meta_function mf = static_cast<meta_function>(i); meta_function mf = static_cast<meta_function>(i);
bool& prop = properties[i];
const std::string& mfname = to_string(mf); const std::string& mfname = to_string(mf);
if (mfname == reg.name) { if (mfname == reg.name) {
switch (mf) { switch (mf) {
case meta_function::construct: case meta_function::construct:
if (prop) { if (properties[i]) {
#ifndef SOL_NO_EXCEPTIONS #ifndef SOL_NO_EXCEPTIONS
throw error("sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems"); throw error("sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
#else #else
@ -490,17 +490,17 @@ namespace sol {
case meta_function::index: case meta_function::index:
indexfunc = reg.func; indexfunc = reg.func;
mustindex = true; mustindex = true;
prop = true; properties.set(i);
return; return;
case meta_function::new_index: case meta_function::new_index:
newindexfunc = reg.func; newindexfunc = reg.func;
mustindex = true; mustindex = true;
prop = true; properties.set(i);
return; return;
default: default:
break; break;
} }
prop = true; properties.set(i);
break; break;
} }
} }
@ -511,7 +511,7 @@ namespace sol {
template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == sizeof...(Tn)>> template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == sizeof...(Tn)>>
usertype_metatable(Args&&... args) usertype_metatable(Args&&... args)
: usertype_metatable_core(&usertype_detail::indexing_fail<T, true>, &usertype_detail::metatable_newindex<T, false>), usertype_detail::registrar(), functions(std::forward<Args>(args)...), destructfunc(nullptr), callconstructfunc(nullptr), indexbase(&core_indexing_call<true>), newindexbase(&core_indexing_call<false>), indexbaseclasspropogation(usertype_detail::walk_all_bases<true>), newindexbaseclasspropogation(usertype_detail::walk_all_bases<false>), baseclasscheck(nullptr), baseclasscast(nullptr), secondarymeta(contains_variable()), properties() { : usertype_metatable_core(&usertype_detail::indexing_fail<T, true>, &usertype_detail::metatable_newindex<T, false>), usertype_detail::registrar(), functions(std::forward<Args>(args)...), destructfunc(nullptr), callconstructfunc(nullptr), indexbase(&core_indexing_call<true>), newindexbase(&core_indexing_call<false>), indexbaseclasspropogation(usertype_detail::walk_all_bases<true>), newindexbaseclasspropogation(usertype_detail::walk_all_bases<false>), baseclasscheck(nullptr), baseclasscast(nullptr), secondarymeta(contains_variable()), properties() {
properties.fill(false); properties.reset();
std::initializer_list<typename usertype_detail::mapping_t::value_type> ilist{{std::pair<std::string, usertype_detail::call_information>(usertype_detail::make_string(std::get<I * 2>(functions)), std::initializer_list<typename usertype_detail::mapping_t::value_type> ilist{{std::pair<std::string, usertype_detail::call_information>(usertype_detail::make_string(std::get<I * 2>(functions)),
usertype_detail::call_information(&usertype_metatable::real_find_call<I * 2, I * 2 + 1, true>, usertype_detail::call_information(&usertype_metatable::real_find_call<I * 2, I * 2 + 1, true>,
&usertype_metatable::real_find_call<I * 2, I * 2 + 1, false>))}...}; &usertype_metatable::real_find_call<I * 2, I * 2 + 1, false>))}...};