mirror of https://github.com/godotengine/godot
Use the in-built casting instead of `dynamic_cast` on all platforms
The in-built casting appears significantly faster than `dynamic_cast`. Co-authored-by: Lukas Tenbrink <lukas.tenbrink@gmail.com>
This commit is contained in:
parent
761339b001
commit
be6f971f4f
|
|
@ -262,6 +262,16 @@ public: \
|
|||
\
|
||||
private:
|
||||
|
||||
// This is a barebones version of GDCLASS,
|
||||
// only intended for simple classes deriving from Object
|
||||
// so that they can support the `Object::cast_to()` method.
|
||||
#define GDSOFTCLASS(m_class, m_inherits) \
|
||||
public: \
|
||||
typedef m_class self_type; \
|
||||
virtual bool is_class_ptr(void *p_ptr) const { return (p_ptr == get_class_ptr_static()) ? true : m_inherits::is_class_ptr(p_ptr); } \
|
||||
\
|
||||
private:
|
||||
|
||||
#define GDCLASS(m_class, m_inherits) \
|
||||
private: \
|
||||
void operator=(const m_class &p_rval) {} \
|
||||
|
|
@ -609,30 +619,26 @@ public:
|
|||
|
||||
template <class T>
|
||||
static T *cast_to(Object *p_object) {
|
||||
#ifndef NO_SAFE_CAST
|
||||
return dynamic_cast<T *>(p_object);
|
||||
#else
|
||||
static_assert(std::is_base_of<Object, T>::value, "T must be derived from Object");
|
||||
static_assert(std::is_same<std::decay_t<T>, typename T::self_type>::value, "T must use GDCLASS or GDSOFTCLASS");
|
||||
if (!p_object)
|
||||
return NULL;
|
||||
if (p_object->is_class_ptr(T::get_class_ptr_static()))
|
||||
return static_cast<T *>(p_object);
|
||||
else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static const T *cast_to(const Object *p_object) {
|
||||
#ifndef NO_SAFE_CAST
|
||||
return dynamic_cast<const T *>(p_object);
|
||||
#else
|
||||
static_assert(std::is_base_of<Object, T>::value, "T must be derived from Object");
|
||||
static_assert(std::is_same<std::decay_t<T>, typename T::self_type>::value, "T must use GDCLASS or GDSOFTCLASS");
|
||||
if (!p_object)
|
||||
return NULL;
|
||||
if (p_object->is_class_ptr(T::get_class_ptr_static()))
|
||||
return static_cast<const T *>(p_object);
|
||||
else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
enum {
|
||||
|
|
|
|||
|
|
@ -200,6 +200,8 @@
|
|||
// CameraFeedOSX - Subclass for camera feeds in OSX
|
||||
|
||||
class CameraFeedOSX : public CameraFeed {
|
||||
GDSOFTCLASS(CameraFeedOSX, CameraFeed);
|
||||
|
||||
private:
|
||||
AVCaptureDevice *device;
|
||||
MyCaptureSession *capture_session;
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@
|
|||
class CryptoMbedTLS;
|
||||
class SSLContextMbedTLS;
|
||||
class CryptoKeyMbedTLS : public CryptoKey {
|
||||
GDSOFTCLASS(CryptoKeyMbedTLS, CryptoKey);
|
||||
|
||||
private:
|
||||
mbedtls_pk_context pkey;
|
||||
int locks = 0;
|
||||
|
|
@ -73,6 +75,8 @@ public:
|
|||
};
|
||||
|
||||
class X509CertificateMbedTLS : public X509Certificate {
|
||||
GDSOFTCLASS(X509CertificateMbedTLS, X509Certificate);
|
||||
|
||||
private:
|
||||
mbedtls_x509_crt cert;
|
||||
int locks;
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ protected:
|
|||
CNAME *(*CNAME::_create)() = NULL;
|
||||
|
||||
#define GDCIIMPL(IMPNAME, CNAME) \
|
||||
GDSOFTCLASS(IMPNAME, CNAME) \
|
||||
public: \
|
||||
static CNAME *_create() { return memnew(IMPNAME); } \
|
||||
static void make_default() { CNAME::_create = IMPNAME::_create; } \
|
||||
|
|
|
|||
|
|
@ -125,6 +125,8 @@ public:
|
|||
/*************************************************************************/
|
||||
|
||||
class CodeSignBlob : public Reference {
|
||||
GDSOFTCLASS(CodeSignBlob, Reference);
|
||||
|
||||
public:
|
||||
virtual PoolByteArray get_hash_sha1() const = 0;
|
||||
virtual PoolByteArray get_hash_sha256() const = 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue