[Webkit-unassigned] [Bug 28455] ThreadTimer: avoid blocking UI when too many timers ready to fire

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Aug 19 14:11:05 PDT 2009


https://bugs.webkit.org/show_bug.cgi?id=28455





--- Comment #5 from Yong Li <yong.li at torchmobile.com>  2009-08-19 14:11:02 PDT ---

> > +    for (Vector<TimerBeingFired>::const_iterator i = firingTimers.begin(); i != firingTimers.end(); ++i) {
> > +        TimerBase* timer = i->m_timer;
> 
> >      for (size_t i = 0; i != size; ++i) {
> >          TimerBase* timer = firingTimers[i];
> 
> We do not normally use iterators to go through a Vector. Instead we just use
> indexing as you would with an array. That's what we did in the existing code,
> and there's no reason to change that just because the timers are a struct.

I agree with the rest of your suggestions. but for this one I think using
iterator (or const_iterator) should be better.

First, "iterator" is kind of standard way for enumerating a C++ container. 

typedef Vector<some type> MyContainerType; 

for (MyContainerType::const_iterator i = container.begin(); i !=
container.end(); ++i) {
}

If someday you change the container type from Vector to List, you don't have to
change the code that enumerates the container.

Second, I think the fastest way of walking through an array is using an
increasing pointer instead of an index, because array[i] may require i *
sizeof(T) to get the address of the element. Although some compilers can be
smart enough to optimize this, I saw replacing array index with increasing
pointer boosted performance in practice. Vector<T>::iterator is just a pointer
T*, and so that it doesn't rely on how smart the compiler is to make the code
run faster.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list