Просмотр исходного кода

meta:
* avoid copies from meta_type::invoke (small perf improvement)
* meta_handle::operator* no longer available
* added meta_handle::operator bool

Michele Caini 5 лет назад
Родитель
Сommit
5c46ccb37e
3 измененных файлов с 9 добавлено и 9 удалено
  1. 5 5
      src/entt/meta/meta.hpp
  2. 1 1
      test/entt/meta/meta_any.cpp
  3. 3 3
      test/entt/meta/meta_handle.cpp

+ 5 - 5
src/entt/meta/meta.hpp

@@ -792,11 +792,11 @@ struct meta_handle {
     }
 
     /**
-     * @brief Dereference operator for accessing the contained opaque object.
-     * @return A meta any that shares a reference to an unmanaged object.
+     * @brief Returns false if a handle is invalid, true otherwise.
+     * @return False if the handle is invalid, true otherwise.
      */
-    [[nodiscard]] meta_any operator*() const {
-        return any;
+    [[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
+        return static_cast<bool>(any);
     }
 
     /**
@@ -1550,7 +1550,7 @@ public:
             }
         }
 
-        return (candidate && !ambiguous) ? candidate->invoke(instance, args) : meta_any{};
+        return (candidate && !ambiguous) ? candidate->invoke(std::move(instance), args) : meta_any{};
     }
 
     /**

+ 1 - 1
test/entt/meta/meta_any.cpp

@@ -746,7 +746,7 @@ TEST_F(MetaAny, ConstConvert) {
 TEST_F(MetaAny, UnmanageableType) {
     unmanageable_t instance;
     entt::meta_any any{std::ref(instance)};
-    entt::meta_any other = any;
+    entt::meta_any other = as_ref(any);
 
     std::swap(any, other);
 

+ 3 - 3
test/entt/meta/meta_handle.cpp

@@ -26,12 +26,12 @@ TEST_F(MetaHandle, Functionalities) {
     clazz_t instance{};
     entt::meta_handle handle{};
 
-    ASSERT_FALSE(*handle);
+    ASSERT_FALSE(handle);
 
     handle = entt::meta_handle{instance};
 
-    ASSERT_TRUE(*handle);
-    ASSERT_TRUE((*handle).invoke("incr"_hs));
+    ASSERT_TRUE(handle);
+    ASSERT_TRUE(handle->invoke("incr"_hs));
     ASSERT_EQ(instance.value, 1);
 
     entt::meta_any any{std::ref(instance)};