further simplify and add comments

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28655 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2009-09-10 15:30:55 +00:00
parent 99a9887e35
commit b510b0d659

View file

@ -931,8 +931,7 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now)
*/ */
now = GSTimeNow(); now = GSTimeNow();
/* /* Fire housekeeping timer as necessary
* Fire housekeeping timer as necessary
*/ */
if ((t = context->housekeeper) != nil) if ((t = context->housekeeper) != nil)
{ {
@ -949,24 +948,19 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now)
} }
} }
/* Remove invalidated timers. /* Fire the oldest/first valid timer whose fire date has passed
*/ * and fire it.
i = GSIArrayCount(timers); * We fire timers in the order in which they were added to the
while (i-- > 0) * run loop rather than in date order. This prevents code
{ * from blocking other timers by adding timers whose fire date
t = GSIArrayItemAtIndex(timers, i).obj; * is some time in the past... we guarantee fair handling.
if (timerInvalidated(t) == YES)
{
GSIArrayRemoveItemAtIndex(timers, i);
}
}
/* Fire the oldest timer whose fire date has passed.
*/ */
c = GSIArrayCount(timers); c = GSIArrayCount(timers);
for (i = 0; i < c; i++) for (i = 0; i < c; i++)
{ {
t = GSIArrayItemAtIndex(timers, i).obj; t = GSIArrayItemAtIndex(timers, i).obj;
if (timerInvalidated(t) == NO)
{
d = timerDate(t); d = timerDate(t);
ti = [d timeIntervalSinceReferenceDate]; ti = [d timeIntervalSinceReferenceDate];
if (ti < now) if (ti < now)
@ -979,7 +973,8 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now)
{ {
/* Updated ... replace in array. /* Updated ... replace in array.
*/ */
GSIArrayAddItemNoRetain(timers, (GSIArrayItem)((id)t)); GSIArrayAddItemNoRetain(timers,
(GSIArrayItem)((id)t));
} }
else else
{ {
@ -992,8 +987,11 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now)
break; break;
} }
} }
}
/* Now, find the earliest fire date. /* Now, find the earliest remaining timer date while removing
* any invalidated timers. We iterate from the end of the
* array to minimise the amount of array alteration needed.
*/ */
earliest = nil; earliest = nil;
i = GSIArrayCount(timers); i = GSIArrayCount(timers);