Changeset 506d2f for src/Helpers


Ignore:
Timestamp:
Aug 4, 2010, 2:43:44 PM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
680470
Parents:
00fca3
Message:

Speed up of ASSERT macro by only calling the _my_assert::check() function when an assertion needs to be handled

Location:
src/Helpers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Helpers/Assert.cpp

    r00fca3 r506d2f  
    5959const char* Assert::_wrapper::message_ref = "source reference did not contain object of desired type";
    6060
    61 bool Assert::_my_assert::check(const bool res,
    62                        const char* condition,
    63                        const char* message,
    64                        const char* filename,
    65                        const int line,
    66                        bool& ignore)
     61bool Assert::_my_assert::check(const char* condition,
     62                               const char* message,
     63                               const char* filename,
     64                               const int line,
     65                               bool& ignore)
    6766{
    68   if(!res){
    69     cout << "Assertion \"" << condition << "\" failed in file " << filename << " at line " << line << endl;
    70     cout << "Assertion Message: " << message << std::endl;
    71     while(true){
    72       char choice;
    73       if(defaultAction==Assert::Ask) {
     67  cout << "Assertion \"" << condition << "\" failed in file " << filename << " at line " << line << endl;
     68  cout << "Assertion Message: " << message << std::endl;
     69  while(true){
     70    char choice;
     71    if(defaultAction==Assert::Ask) {
    7472#ifdef __GNUC__
    75         cout << "Please choose: (a)bort, (t)hrow execption, show (b)actrace, (i)gnore, al(w)ays ignore" << endl;
     73      cout << "Please choose: (a)bort, (t)hrow execption, show (b)actrace, (i)gnore, al(w)ays ignore" << endl;
    7674#else
    77         cout << "Please choose: (a)bort, (t)hrow execption, (i)gnore, al(w)ays ignore" << endl;
     75      cout << "Please choose: (a)bort, (t)hrow execption, (i)gnore, al(w)ays ignore" << endl;
    7876#endif /* __GNUC__ */
    79         cin >> choice;
    80       }
    81       else{
    82         choice = ActionKeys[defaultAction];
    83       }
    84       switch(choice){
    85         case 'a':
    86           return true;
    87           break;
    88         case 't':
    89           throw AssertionFailure(condition,filename,line,message);
    90           break;
     77      cin >> choice;
     78    }
     79    else{
     80      choice = ActionKeys[defaultAction];
     81    }
     82    switch(choice){
     83      case 'a':
     84        return true;
     85        break;
     86      case 't':
     87        throw AssertionFailure(condition,filename,line,message);
     88        break;
    9189#ifdef __GNUC__
    92         case 'b':
    93           Assert::_my_assert::backtrace(filename,line);
    94          break;
     90      case 'b':
     91        Assert::_my_assert::backtrace(filename,line);
     92       break;
    9593#endif /* __GNUC__ */
    96         case 'w':
    97           ignore = true;
    98           // fallthrough
    99         case 'i':
    100           return false;
    101           break;
    102       }
     94      case 'w':
     95        ignore = true;
     96        // fallthrough
     97      case 'i':
     98        return false;
     99        break;
    103100    }
    104101  }
  • src/Helpers/Assert.hpp

    r00fca3 r506d2f  
    234234      static bool ignore = false;\
    235235      if(!ignore){\
    236         if(Assert::_my_assert::check((condition),STRINGIFY(condition),(message),\
    237                                      __FILE__,__LINE__,ignore)){\
     236        if(!(condition) && Assert::_my_assert::check(STRINGIFY(condition),(message),\
     237                                                     __FILE__,__LINE__,ignore)){\
    238238          Assert::_my_assert::doHooks();\
    239239          DEBUG_BREAK;\
     
    247247                  static bool ignore = false; \
    248248                  if(!ignore){\
    249                           if(Assert::_my_assert::check(false,"Exception caught",(message),__FILE__,__LINE__,ignore)){\
     249                          if(Assert::_my_assert::check("Exception caught",(message),__FILE__,__LINE__,ignore)){\
    250250                            Assert::_my_assert::doHooks();\
    251           DEBUG_BREAK;\
     251                            DEBUG_BREAK;\
    252252                          }\
    253253                  }\
     
    299299    class _my_assert{
    300300    public:
    301       static bool check(const bool res,
    302                         const char* condition,
     301      static bool check(const char* condition,
    303302                        const char* message,
    304303                        const char* filename,
     
    335334
    336335      if(!ignore){
    337         if(_my_assert::check(dynamic_cast<target>(src)==static_cast<target>(src),"type-safe typecast",
    338                                        message_ptr,file,line,ignore)){
     336        bool res = dynamic_cast<target>(src)==static_cast<target>(src);
     337        if(!res && _my_assert::check("type-safe typecast",message_ptr,file,line,ignore)){
    339338          _my_assert::doHooks();
    340339          DEBUG_BREAK;
     
    357356      catch(...){
    358357        if(!ignore){
    359           if(_my_assert::check(0,"type-safe typecast",message_ref,file,line,ignore)){
     358          if(_my_assert::check("type-safe typecast",message_ref,file,line,ignore)){
    360359            _my_assert::doHooks();
    361360            DEBUG_BREAK;
Note: See TracChangeset for help on using the changeset viewer.