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:
King_DuckZ 2022-06-03 09:53:28 +02:00
parent 09530e15c9
commit b3ecb69ec0
4 changed files with 11 additions and 12 deletions

View file

@ -52,9 +52,11 @@ namespace wren {
//spits out.
class ModuleAndName {
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:
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;
@ -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 class_name() const noexcept { return {class_name_char(), m_class_name_len}; }
constexpr const char* buffer_address() const noexcept { return m_base; }
constexpr ModuleAndNameHashType hash() const noexcept { return m_hash; }
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;
const char* m_base;
@ -102,6 +105,10 @@ namespace wren {
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) :
m_base(base),
m_hash(hash),
@ -139,7 +146,7 @@ namespace wren {
}
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 StaticStorage = detail::ModuleAndNameStaticStorage<S1 + string("\0") + S2>;

View file

@ -20,12 +20,6 @@
#include <cstdint>
namespace wren {
//template <typename U>
//[[gnu::const]]
//inline constexpr std::uint32_t type_hash() {
// return crc32c(__PRETTY_FUNCTION__);
//}
//from:
//https://codereview.stackexchange.com/questions/48594/unique-type-id-no-rtti
class TypeID {

View file

@ -16,7 +16,6 @@
*/
#include "wrenpp/class_manager.hpp"
#include "wrenpp/detail/crc32.hpp"
#include <cassert>
namespace wren {
@ -41,7 +40,6 @@ namespace wren {
ClassNameOwning::operator ModuleAndName() const {
return ModuleAndName{
this->raw_buffer(),
crc32c(this->raw_buffer(), this->raw_buffer_size()),
this->module_name().size(),
this->class_name().size()
};

View file

@ -119,7 +119,7 @@ namespace wren {
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