Ticket #1064 (closed enhancement: fixed)
[PATCH] Performance improvement. It is more effective to use the prefix form of ++iterator (vs iterator++)
|Reported by:||Echelon9||Owned by:|
|Priority:||Should Have||Milestone:||Alpha 9|
|Component:||Core engine||Keywords:||review, STL|
An iterator is changed in the program code by the increment/decrement postfix operator. Since the previous iterator's value is not used, you may replace the postfix operator with the prefix one. In some cases, the prefix operator will work faster than the postfix one, especially in Debug-versions.
The prefix increment operator changes the object's state and returns itself already changed.
The situation with the postfix increment operator is more complicated. The object's state must change but it is the previous state which is returned. So an additional temporary object is created.
Reference: Scott Meyers' Rule 6. Distinguish between prefix increment and decrement operators, in:
Meyers, Scott. More Effective C++: 35 New Ways to Improve Your Programs and Designs. Addison-Wesley, Reading, Mass., 1996. ISBN-10: 020163371X. ISBN-13: 9780201633719.