From kde-devel Tue Jul 15 12:33:50 2003 From: Tim Jansen Date: Tue, 15 Jul 2003 12:33:50 +0000 To: kde-devel Subject: Re: QPtrList documentation X-MARC-Message: https://marc.info/?l=kde-devel&m=105827293206268 On Tuesday 15 July 2003 12:33, Adriaan de Groot wrote: > while the documentation for QPtrList::at() states > This function is very efficient. It starts scanning from the first item, > last item, or current item, whichever is closest to index. > now, what could the inefficiency referred to in the example be? If at() > used to do a linear search from the beginning of the list, then I can > imagine the comment to be correct. Look at the source code :) The loop should be quite efficient, because of the implementation of QPtrList::at(int). It caches the position of one node, called the current node. When you access a node that is near the current node, it will start from the current node (and not the beginning or the end of the list). After using at(int) the requested node will be the new current node. And QPtrList::count() just returns a member with the length. So the performance in the loop will always be o(1) per iteration. In other words, it's not that slow. But using an iterator should still be faster, because it will need execute code. bye... >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<