فهرست منبع

meta: slightly faster non-const typed allow_cast

skypjack 11 ساعت پیش
والد
کامیت
b56e3a165b
1فایلهای تغییر یافته به همراه9 افزوده شده و 12 حذف شده
  1. 9 12
      src/entt/meta/meta.hpp

+ 9 - 12
src/entt/meta/meta.hpp

@@ -505,21 +505,18 @@ public:
      */
      */
     template<typename Type>
     template<typename Type>
     [[nodiscard]] bool allow_cast() {
     [[nodiscard]] bool allow_cast() {
-        if constexpr(stl::is_reference_v<Type> && !stl::is_const_v<stl::remove_reference_t<Type>>) {
-            return allow_cast<const stl::remove_reference_t<Type> &>() && (storage.policy() != any_policy::cref);
-        } else {
-            if(storage.has_value<stl::remove_cvref_t<Type>>()) {
-                return true;
-            } else if(auto other = stl::as_const(*this).allow_cast<stl::remove_cvref_t<Type>>(); other) {
-                if(other.storage.owner()) {
-                    stl::swap(*this, other);
-                }
-
-                return true;
+        if(storage.has_value<stl::remove_cvref_t<Type>>()) {
+            constexpr auto no_check = !stl::is_reference_v<Type> || stl::is_const_v<stl::remove_reference_t<Type>>;
+            return no_check || (storage.policy() != any_policy::cref);
+        } else if(auto other = stl::as_const(*this).allow_cast<stl::remove_cvref_t<Type>>(); other) {
+            if(other.storage.owner()) {
+                stl::swap(*this, other);
             }
             }
 
 
-            return false;
+            return true;
         }
         }
+
+        return false;
     }
     }
 
 
     /*! @copydoc any::emplace */
     /*! @copydoc any::emplace */