rice/detail/NativeRegistry.ipp in rice-4.3.2 vs rice/detail/NativeRegistry.ipp in rice-4.3.3

- old
+ new

@@ -8,38 +8,30 @@ #include "RubyFunction.hpp" namespace Rice::detail { - // Effective Java (2nd edition) - // https://stackoverflow.com/a/2634715 - inline size_t NativeRegistry::key(VALUE klass, ID id) - { - uint32_t prime = 53; - return (prime + klass) * prime + id; - } - inline void NativeRegistry::add(VALUE klass, ID method_id, std::any callable) { if (rb_type(klass) == T_ICLASS) { klass = detail::protect(rb_class_of, klass); } - auto range = this->natives_.equal_range(key(klass, method_id)); + auto range = this->natives_.equal_range(method_id); for (auto it = range.first; it != range.second; ++it) { - const auto [k, m, d] = it->second; + const auto [k, d] = it->second; - if (k == klass && m == method_id) + if (k == klass) { - std::get<2>(it->second) = callable; + std::get<1>(it->second) = callable; return; } } - this->natives_.emplace(std::make_pair(key(klass, method_id), std::make_tuple(klass, method_id, callable))); + this->natives_.emplace(std::make_pair(method_id, std::make_pair(klass, callable))); } template <typename Return_T> inline Return_T NativeRegistry::lookup() { @@ -59,15 +51,15 @@ if (rb_type(klass) == T_ICLASS) { klass = detail::protect(rb_class_of, klass); } - auto range = this->natives_.equal_range(key(klass, method_id)); + auto range = this->natives_.equal_range(method_id); for (auto it = range.first; it != range.second; ++it) { - const auto [k, m, d] = it->second; + const auto [k, d] = it->second; - if (k == klass && m == method_id) + if (k == klass) { auto* ptr = std::any_cast<Return_T>(&d); if (!ptr) { rb_raise(rb_eRuntimeError, "Unexpected return type for %s#%s", rb_class2name(klass), rb_id2name(method_id));