Keeping crc around, but cleaning up a bit
Crc is used as an optimisation for operator==, which is legit. Either way, the struct's size would still be 16 even without the crc (the variable would just became an always 0 "reserved"). Crc's use is limited to here anyways, so for now it's not harming anyone.
This commit is contained in:
parent
09530e15c9
commit
b3ecb69ec0
4 changed files with 11 additions and 12 deletions
|
@ -52,9 +52,11 @@ namespace wren {
|
||||||
//spits out.
|
//spits out.
|
||||||
class ModuleAndName {
|
class ModuleAndName {
|
||||||
friend bool detail::deep_equal(const ModuleAndName&, const ModuleAndName&) noexcept;
|
friend bool detail::deep_equal(const ModuleAndName&, const ModuleAndName&) noexcept;
|
||||||
|
template <dhandy::bt::string S1, dhandy::bt::string S2>
|
||||||
|
friend consteval ModuleAndName make_module_and_name() noexcept;
|
||||||
public:
|
public:
|
||||||
constexpr ModuleAndName();
|
constexpr ModuleAndName();
|
||||||
constexpr ModuleAndName (const char* base, ModuleAndNameHashType hash, std::size_t mod_name_len, std::size_t class_name_len);
|
constexpr ModuleAndName (const char* base, std::size_t mod_name_len, std::size_t class_name_len);
|
||||||
|
|
||||||
constexpr bool operator==(const ModuleAndName& other) const noexcept;
|
constexpr bool operator==(const ModuleAndName& other) const noexcept;
|
||||||
constexpr bool operator!=(const ModuleAndName& other) const noexcept;
|
constexpr bool operator!=(const ModuleAndName& other) const noexcept;
|
||||||
|
@ -67,9 +69,10 @@ namespace wren {
|
||||||
constexpr std::string_view module_name() const noexcept { return {module_name_char(), m_mod_name_len}; }
|
constexpr std::string_view module_name() const noexcept { return {module_name_char(), m_mod_name_len}; }
|
||||||
constexpr std::string_view class_name() const noexcept { return {class_name_char(), m_class_name_len}; }
|
constexpr std::string_view class_name() const noexcept { return {class_name_char(), m_class_name_len}; }
|
||||||
constexpr const char* buffer_address() const noexcept { return m_base; }
|
constexpr const char* buffer_address() const noexcept { return m_base; }
|
||||||
constexpr ModuleAndNameHashType hash() const noexcept { return m_hash; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
constexpr ModuleAndName (const char* base, ModuleAndNameHashType hash, std::size_t mod_name_len, std::size_t class_name_len);
|
||||||
|
|
||||||
constexpr std::size_t raw_buffer_size() const noexcept;
|
constexpr std::size_t raw_buffer_size() const noexcept;
|
||||||
|
|
||||||
const char* m_base;
|
const char* m_base;
|
||||||
|
@ -102,6 +105,10 @@ namespace wren {
|
||||||
ModuleAndName(nullptr, 0, 0, 0)
|
ModuleAndName(nullptr, 0, 0, 0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
constexpr ModuleAndName::ModuleAndName (const char* base, std::size_t mod_name_len, std::size_t class_name_len) :
|
||||||
|
ModuleAndName(base, crc32c(base, mod_name_len + class_name_len + 2), mod_name_len, class_name_len)
|
||||||
|
{}
|
||||||
|
|
||||||
constexpr ModuleAndName::ModuleAndName (const char* base, ModuleAndNameHashType hash, std::size_t mod_name_len, std::size_t class_name_len) :
|
constexpr ModuleAndName::ModuleAndName (const char* base, ModuleAndNameHashType hash, std::size_t mod_name_len, std::size_t class_name_len) :
|
||||||
m_base(base),
|
m_base(base),
|
||||||
m_hash(hash),
|
m_hash(hash),
|
||||||
|
@ -139,7 +146,7 @@ namespace wren {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <dhandy::bt::string S1, dhandy::bt::string S2>
|
template <dhandy::bt::string S1, dhandy::bt::string S2>
|
||||||
consteval ModuleAndName make_module_and_name() {
|
consteval ModuleAndName make_module_and_name() noexcept {
|
||||||
using dhandy::bt::string;
|
using dhandy::bt::string;
|
||||||
using StaticStorage = detail::ModuleAndNameStaticStorage<S1 + string("\0") + S2>;
|
using StaticStorage = detail::ModuleAndNameStaticStorage<S1 + string("\0") + S2>;
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,6 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace wren {
|
namespace wren {
|
||||||
//template <typename U>
|
|
||||||
//[[gnu::const]]
|
|
||||||
//inline constexpr std::uint32_t type_hash() {
|
|
||||||
// return crc32c(__PRETTY_FUNCTION__);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//from:
|
//from:
|
||||||
//https://codereview.stackexchange.com/questions/48594/unique-type-id-no-rtti
|
//https://codereview.stackexchange.com/questions/48594/unique-type-id-no-rtti
|
||||||
class TypeID {
|
class TypeID {
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "wrenpp/class_manager.hpp"
|
#include "wrenpp/class_manager.hpp"
|
||||||
#include "wrenpp/detail/crc32.hpp"
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
namespace wren {
|
namespace wren {
|
||||||
|
@ -41,7 +40,6 @@ namespace wren {
|
||||||
ClassNameOwning::operator ModuleAndName() const {
|
ClassNameOwning::operator ModuleAndName() const {
|
||||||
return ModuleAndName{
|
return ModuleAndName{
|
||||||
this->raw_buffer(),
|
this->raw_buffer(),
|
||||||
crc32c(this->raw_buffer(), this->raw_buffer_size()),
|
|
||||||
this->module_name().size(),
|
this->module_name().size(),
|
||||||
this->class_name().size()
|
this->class_name().size()
|
||||||
};
|
};
|
||||||
|
|
|
@ -119,7 +119,7 @@ namespace wren {
|
||||||
source_mem = &*dst.insert(it_found, std::move(new_entry));
|
source_mem = &*dst.insert(it_found, std::move(new_entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {source_mem->data(), 0, mod_name.size(), cls_name.size()};
|
return {source_mem->data(), mod_name.size(), cls_name.size()};
|
||||||
}
|
}
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue