On Tuesday, November 01, 2011 11:15:15 Aaron J. Seigo wrote: > On Tuesday, November 1, 2011 10:45:27 Sebastian Kügler wrote: > > http://harmattan- > > dev.nokia.com/docs/library/html/guide/html/Developer_Library_Best_practic > > es_ for_application_development_QML_performance_tips_and_tricks.html > > some nice points in there indeed .. > > i did spot a common programming error in the last bit on container usage, > however: > > QStringList nameList=myClass.nameList(); > if ( nameList.first()==searchName ) { > ... > } > > first() and at(0) will both trigger asserts / crash if the list is empty. > if using first() or at(0) always do it like this: > > if (!nameList.isEmpty() && nameList.at(0) == searchName()) > > at(int) assumes a valid index (for performance reasons) similar to how > arrays in C do. this has hit people many times in plasma code. watch out > :)
Well spot. Not such a big issue in there, though, since the doc says "avoid this pattern", just one more reason to do so :) > also, when iterating a list i usually just use Q*Iterator with their java- > style notation. they are harder to get wrong, the code is shorter and > easier to read and the overhead is nominal. The good examples use iterators, yep. -- sebas http://www.kde.org | http://vizZzion.org | GPG Key ID: 9119 0EF9 _______________________________________________ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel