summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/extensible.h6
-rw-r--r--include/services.h17
-rw-r--r--include/sysconf.h.cmake2
3 files changed, 22 insertions, 3 deletions
diff --git a/include/extensible.h b/include/extensible.h
index 523a25b6d..5ab32c6eb 100644
--- a/include/extensible.h
+++ b/include/extensible.h
@@ -153,7 +153,7 @@ class CoreExport Extensible
if (it != this->Extension_Items.end())
{
- p = dynamic_cast<ExtensibleItemRegular<T> *>(it->second)->GetItem();
+ p = debug_cast<ExtensibleItemRegular<T> *>(it->second)->GetItem();
return true;
}
@@ -172,7 +172,7 @@ class CoreExport Extensible
if (it != this->Extension_Items.end())
{
- p = dynamic_cast<ExtensibleItemPointer<T> *>(it->second)->GetItem();
+ p = debug_cast<ExtensibleItemPointer<T> *>(it->second)->GetItem();
return true;
}
@@ -192,7 +192,7 @@ class CoreExport Extensible
if (it != this->Extension_Items.end())
{
- p = dynamic_cast<ExtensibleItemPointerArray<T> *>(it->second)->GetItem();
+ p = debug_cast<ExtensibleItemPointerArray<T> *>(it->second)->GetItem();
return true;
}
diff --git a/include/services.h b/include/services.h
index 16f365a09..8e1adcf01 100644
--- a/include/services.h
+++ b/include/services.h
@@ -41,6 +41,7 @@
#include <sys/types.h>
#include <assert.h>
#include <fcntl.h>
+#include <typeinfo>
#ifndef _WIN32
# include <unistd.h>
@@ -268,6 +269,22 @@ class DatabaseException : public CoreException
virtual ~DatabaseException() throw() { }
};
+/** Debug cast to be used instead of dynamic_cast, this uses dynamic_cast
+ * for debug builds and static_cast on releass builds to speed up the program
+ * because dynamic_cast relies on RTTI.
+ */
+template<typename T, typename O> inline T debug_cast(O ptr)
+{
+#ifdef DEBUG_BUILD
+ T ret = dynamic_cast<T>(ptr);
+ if (ret == NULL)
+ throw CoreException(Anope::string("debug_cast<") + typeid(T).name() + ">(" + typeid(O).name() + ") fail");
+ return ret;
+#else
+ return static_cast<T>(ptr);
+#endif
+}
+
/*************************************************************************/
/** Class with the ability to keep flags on items, they should extend from this
diff --git a/include/sysconf.h.cmake b/include/sysconf.h.cmake
index 5884a3284..0184c5359 100644
--- a/include/sysconf.h.cmake
+++ b/include/sysconf.h.cmake
@@ -1,6 +1,8 @@
#ifndef _SYSCONF_H_
#define _SYSCONF_H_
+#cmakedefine DEBUG_BUILD
+
#cmakedefine DEFUMASK @DEFUMASK@
#cmakedefine HAVE_SYS_TYPES_H 1
#cmakedefine HAVE_STDINT_H 1