From 185c30c85bf5e5efe9f400d7712f9eb8c7b8585b Mon Sep 17 00:00:00 2001 From: ulfjorensen Date: Wed, 6 Jan 2010 22:04:31 +0000 Subject: [PATCH] Bugfix: moved ai_assert condition evaluation out of the assert function to avoid constructing two expensive strings on every single call. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@525 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/ValidateDataStructure.cpp | 2 +- code/aiAssert.cpp | 12 +++++++----- include/aiAssert.h | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/code/ValidateDataStructure.cpp b/code/ValidateDataStructure.cpp index 3719d0b68..3076b8fe3 100644 --- a/code/ValidateDataStructure.cpp +++ b/code/ValidateDataStructure.cpp @@ -87,7 +87,7 @@ void ValidateDSProcess::ReportError(const char* msg,...) va_end(args); #ifdef _DEBUG - aiAssert( false,szBuffer,__LINE__,__FILE__ ); + aiAssert( szBuffer,__LINE__,__FILE__ ); #endif throw new ImportErrorException("Validation failed: " + std::string(szBuffer,iLen)); } diff --git a/code/aiAssert.cpp b/code/aiAssert.cpp index f71ec6366..29f4279d7 100644 --- a/code/aiAssert.cpp +++ b/code/aiAssert.cpp @@ -10,12 +10,14 @@ // Set a breakpoint using win32, else line, file and message will be returned and progam ends with // errrocode = 1 -void Assimp::aiAssert (bool expression, const std::string &message, unsigned int uiLine, const std::string &file) +void Assimp::aiAssert (const std::string &message, unsigned int uiLine, const std::string &file) { - if (!expression) - { - // FIX (Aramis): changed std::cerr to std::cout that the message appears in VS' output window ... - std::cout << "File :" << file << ", line " << uiLine << " : " << message << std::endl; + // moved expression testing out of the function and into the macro to avoid constructing + // two std::string on every single ai_assert test +// if (!expression) + { + // FIX (Aramis): changed std::cerr to std::cout that the message appears in VS' output window ... + std::cout << "File :" << file << ", line " << uiLine << " : " << message << std::endl; #ifdef _WIN32 #ifndef __GNUC__ diff --git a/include/aiAssert.h b/include/aiAssert.h index 84e64435d..21e806227 100644 --- a/include/aiAssert.h +++ b/include/aiAssert.h @@ -14,13 +14,13 @@ namespace Assimp { //! \brief ASSIMP specific assertion test, only works in debug mode //! \param uiLine Line in file //! \param file Source file -void aiAssert (bool expression, const std::string &message, unsigned int uiLine, const std::string &file); +void aiAssert(const std::string &message, unsigned int uiLine, const std::string &file); //! \def ai_assert //! \brief ASSIM specific assertion test #ifdef DEBUG -# define ai_assert(expression) Assimp::aiAssert (expression, #expression, __LINE__, __FILE__); +# define ai_assert(expression) if( !(expression)) Assimp::aiAssert( #expression, __LINE__, __FILE__); #else # define ai_assert(expression) #endif