From 5c46ccb37e89d583df770f6054748092bb56bb75 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 8 Feb 2021 11:33:53 +0100 Subject: [PATCH] meta: * avoid copies from meta_type::invoke (small perf improvement) * meta_handle::operator* no longer available * added meta_handle::operator bool --- src/entt/meta/meta.hpp | 10 +++++----- test/entt/meta/meta_any.cpp | 2 +- test/entt/meta/meta_handle.cpp | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 2a3db1180..5636c4b57 100644 --- a/src/entt/meta/meta.hpp +++ b/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(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{}; } /** diff --git a/test/entt/meta/meta_any.cpp b/test/entt/meta/meta_any.cpp index 458d5db58..54d2f5126 100644 --- a/test/entt/meta/meta_any.cpp +++ b/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); diff --git a/test/entt/meta/meta_handle.cpp b/test/entt/meta/meta_handle.cpp index aafa50d56..e86c01267 100644 --- a/test/entt/meta/meta_handle.cpp +++ b/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)};