Hi all, I have the following method where I manage various lists: "llistaAccions" is a list containing identificators to the actions that I need to execute sequentally until the previous to the last one. "llistaParamsColors", "llistaParamsRects", "llistaParamsDoubles" and "llistaParamsInts" contain the parameters of each action. Now, I use QMutableListIterators to iterate through the lists but I think that the code can be slighty more efficient because I go through the list sequentally and, also, I need to delete only the last items on each list and not the items in the middle. Here's the code:

Qt Code:
  1. void MyApp::executeAllUntilPrevious()
  2. {
  3. int aux1, aux2, aux3, aux4;
  4. double auxd1, auxd2, auxd3, auxd4;
  5. QImage imatgeEnganxar;
  6.  
  7. llistaAccions.removeLast();
  8.  
  9. QMutableListIterator<IdentificadorAccions> itAccions(llistaAccions);
  10. QMutableListIterator<QColor> itColors(llistaParamsColors);
  11. QMutableListIterator<QRect> itRects(llistaParamsRects);
  12. QMutableListIterator<double> itDoubles(llistaParamsDoubles);
  13. QMutableListIterator<int> itInts(llistaParamsInts);
  14.  
  15. while(itAccions.hasNext())
  16. {
  17. switch(itAccions.next())
  18. {
  19. case Rotat:
  20. rotat(itColors.next(), itDoubles.next());
  21. break;
  22.  
  23. case Retallat:
  24. retallat(itRects.next());
  25. break;
  26.  
  27. case Pintat:
  28. pintat(itColors.next(), itRects.next());
  29. break;
  30.  
  31. case Copiat:
  32. if (itAccions.hasNext())
  33. imatgeEnganxar = foto -> copiarImatge(itRects.next());
  34. else
  35. itAccions.remove();
  36. break;
  37.  
  38. case Enganxat:
  39. enganxat(itRects.next(), imatgeEnganxar);
  40. break;
  41.  
  42. case Restaurat:
  43. restaurat();
  44. break;
  45.  
  46. case EscalatCm:
  47. auxd1 = itDoubles.next();
  48. auxd2 = itDoubles.next();
  49. canviTamanyCm(auxd1, auxd2);
  50. break;
  51.  
  52. case EscalatPixels:
  53. aux1 = itInts.next();
  54. aux2 = itInts.next();
  55. canviTamanyPixels(aux1, aux2);
  56. break;
  57.  
  58. case CanviatResolucioPixelsCm:
  59. aux1 = itInts.next();
  60. aux2 = itInts.next();
  61. canviResolucioPixelsCm(aux1, aux2);
  62. break;
  63.  
  64. case CanviatResolucioPixelsPolzada:
  65. aux1 = itInts.next();
  66. aux2 = itInts.next();
  67. canviResolucioPixelsPolzada(aux1, aux2);
  68. break;
  69.  
  70. case CanviatMargesCm:
  71. auxd1 = itDoubles.next();
  72. auxd2 = itDoubles.next();
  73. auxd3 = itDoubles.next();
  74. auxd4 = itDoubles.next();
  75. canviTamanyMargesCm(itColors.next(), auxd1, auxd2, auxd3, auxd4);
  76. break;
  77.  
  78. case CanviatMargesPixels:
  79. aux1 = itInts.next();
  80. aux2 = itInts.next();
  81. aux3 = itInts.next();
  82. aux4 = itInts.next();
  83. canviTamanyMargesPixels(itColors.next(), aux1, aux2, aux3, aux4);
  84. }
  85. }
  86.  
  87. //This part is a bit "dirty" and I think that could be achieved with just one sentence...
  88. while(itColors.hasNext())
  89. {
  90. itColors.next();
  91. itColors.remove();
  92. }
  93.  
  94. while(itRects.hasNext())
  95. {
  96. itRects.next();
  97. itRects.remove();
  98. }
  99.  
  100. while(itDoubles.hasNext())
  101. {
  102. itDoubles.next();
  103. itDoubles.remove();
  104. }
  105.  
  106. while(itInts.hasNext())
  107. {
  108. itInts.next();
  109. itInts.remove();
  110. }
  111. }
To copy to clipboard, switch view to plain text mode 

Well, I've readed that STL style iterators can be slightly faster than the Java-style iterators (QMutableListIterator). And, inside the STL style iterators, QList::const_iterator is slightly faster than QList::iterator. First of all, do you think that I really need iterators with the code above to obtain a better performance and/or readability? And, in that case, what kind of iterator you think that could fit better in what I need to do: iterate sequentially through the lists and, at the end, delete all the items from the current position until the end. Thanks.