[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: QPtrList documentation
From:       Tim Jansen <ml () tjansen ! de>
Date:       2003-07-15 12:33:50
[Download RAW message or body]

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 <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic