Browse Source

Fixed slow Assert/DebugAssert.

Mark Sibly 9 years ago
parent
commit
ed1428a755
3 changed files with 10 additions and 26 deletions
  1. 2 6
      modules/monkey/debug.monkey2
  2. 3 3
      modules/monkey/native/bbarray.h
  3. 5 17
      modules/monkey/native/bbdebug.h

+ 2 - 6
modules/monkey/debug.monkey2

@@ -18,9 +18,7 @@ Function RuntimeError( message:String )="bbDB::error"
 @param message Runtime error message to generate.
 
 #end
-Function Assert( condition:Bool )="bbAssert"
-
-Function Assert( condition:Bool,message:String )="bbAssert"
+Function Assert( condition:Bool,message:String="Assert failed" )="bbAssert"
 
 #rem monkeydoc Generates a runtime error if a boolean expression is false (Debug builds only).
 
@@ -32,9 +30,7 @@ any critical code.
 @param message Runtime error message to generate.
 
 #end
-Function DebugAssert( condition:Bool )="bbDebugAssert"
-
-Function DebugAssert( condition:Bool,message:String )="bbDebugAssert"
+Function DebugAssert( condition:Bool,message:String="Debug assert failed" )="bbDebugAssert"
 
 #rem monkeydoc Gets the current stack state (Debug builds only).
 

+ 3 - 3
modules/monkey/native/bbarray.h

@@ -84,7 +84,7 @@ template<class T,int D> class bbArray : public bbGCNode{
 	}
 	
 	int size( int q )const{
-		bbDebugAssert( q<D );
+		bbDebugAssert( q<D,"Array dimension out of range" );
 		return this ? (q ? _sizes[q]/_sizes[q-1] : _sizes[0]) : 0;
 	}
 	
@@ -139,7 +139,7 @@ template<class T,int D> class bbArray : public bbGCNode{
 	}
 	
 	//fast 1D version	
-	T &at( int index )const{
+	T &at( int index ){
 		bbDebugAssert( index>=0 && index<length(),"Array index out of range" );
 		return data()[index];
 	}
@@ -147,7 +147,7 @@ template<class T,int D> class bbArray : public bbGCNode{
 	//slower N-D version
 	template<class...Args> T &at( Args...args ){
 	
-		int indices[]{args...};
+		const int indices[]{args...};
 		
 		int index=indices[0];
 		bbDebugAssert( index>=0,"Array index out of range" );

+ 5 - 17
modules/monkey/native/bbdebug.h

@@ -161,24 +161,12 @@ template<class T> void bbDBLocal ( const char *name,T *var ){
 	++bbDB::currentContext->locals;
 }
 
-inline void bbAssert( bool cond ){
-	if( !cond ) bbDB::error( "Assert failed" );
-}
-
-inline void bbAssert( bool cond,bbString msg ){
-	if( !cond ) bbDB::error( msg );
-}
+#define bbAssert( COND,MSG ) (void)((COND) || (bbDB::error(MSG),0))
 
-inline void bbDebugAssert( bool cond ){
-#ifndef NDEBUG
-	if( !cond ) bbDB::error( "DebugAssert failed" );
+#ifdef NDEBUG
+#define bbDebugAssert( COND,MSG )
+#else
+#define bbDebugAssert( COND,MSG ) (void)((COND) || (bbDB::error(MSG),0))
 #endif
-}
-
-inline void bbDebugAssert( bool cond,bbString msg ){
-#ifndef NDEBUG
-	if( !cond ) bbDB::error( msg );
-#endif
-}
 
 #endif