Ignore:
Timestamp:
May 23, 2008, 9:17:19 AM (17 years ago)
Author:
Frederik Heber <heber@…>
Children:
6145aa7
Parents:
6c96f4
Message:

Lots of for loops now count in reverse order where it does not matter, some 3 -> NDIM

for(i=0;i<var;i++) is slower than for (i=var;i--;) if the order of the i's is not important (note: i-- is also a value and it stops when on i == 0 automatically)
in builder.cpp there were some remnant 3 actually meant to be NDIM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified molecuilder/src/moleculelist.cpp

    r6c96f4 rf75030  
    2222{
    2323  ListOfMolecules = (molecule **) Malloc(sizeof(molecule *)*NumMolecules, "MoleculeListClass:MoleculeListClass: **ListOfMolecules");
    24   for (int i=0;i<NumMolecules;i++)
     24  for (int i=NumMolecules;i--;)
    2525    ListOfMolecules[i] = NULL;
    2626  NumberOfMolecules = NumMolecules;
     
    3434{
    3535  cout << Verbose(3) << this << ": Freeing ListOfMolcules." << endl;
    36   for (int i=0;i<NumberOfMolecules;i++) {
     36  for (int i=NumberOfMolecules;i--;) {
    3737    if (ListOfMolecules[i] != NULL) { // if NULL don't free
    3838      cout << Verbose(4) << "ListOfMolecules: Freeing " << ListOfMolecules[i] << "." << endl;
     
    6666    else {
    6767      Count = (**(molecule **)a).AtomCount;
    68       aList = (int *) Malloc(sizeof(int)*Count, "MolCompare: *aList");
    69       bList = (int *) Malloc(sizeof(int)*Count, "MolCompare: *bList");
     68      aList = new int[Count];
     69      bList = new int[Count];
    7070 
    7171      // fill the lists
     
    114114        }
    115115      }
    116       Free((void **)&aList, "MolCompare: *aList");
    117       Free((void **)&bList, "MolCompare: *bList");
     116      delete[](aList);
     117      delete[](bList);
    118118      return flag;
    119119    }
     
    244244    ListOfMolecules[i]->SetBoxDimension(&BoxDimension);  // update Box of atoms by boundary
    245245    int j = -1;
    246     for (int k=0;k<3;k++) {
     246    for (int k=0;k<NDIM;k++) {
    247247      j += k+1;
    248248      BoxDimension.x[k] = 5.;
     
    268268    outputFragment.close();
    269269    outputFragment.clear();
    270     Free((void **)&FragmentNumber, "MoleculeListClass::OutputConfigForListOfFragments: *FragmentNumber");
     270    delete(FragmentNumber);
     271    //Free((void **)&FragmentNumber, "MoleculeListClass::OutputConfigForListOfFragments: *FragmentNumber");
    271272  }
    272273  cout << " done." << endl;
     
    461462    ListOfLocalAtoms = (atom ***) Malloc(sizeof(atom **)*Counter, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");
    462463    if (ListOfLocalAtoms != NULL) {
    463       for (int i=0;i<Counter;i++)
     464      for (int i=Counter;i--;)
    464465        ListOfLocalAtoms[i] = NULL;
    465466      FreeList = FreeList && true;
     
    501502    KeySetCounter = Count();
    502503    FragmentList = (Graph **) Malloc(sizeof(Graph *)*KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList");
    503     for(int i=0;i<KeySetCounter;i++)
     504    for(int i=KeySetCounter;i--;)
    504505      FragmentList[i] = NULL;
    505506    KeySetCounter = 0;
Note: See TracChangeset for help on using the changeset viewer.