mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Tidied
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4111 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
2f0818bebd
commit
2e8a34c705
5 changed files with 53 additions and 52 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Thu Apr 22 11:35:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
|
* Source/NSRunLoop.m: Optimisation and tidyup.
|
||||||
|
* Source/NSTimer.m: Minor bugfixes.
|
||||||
|
* Source/include/FastArray.x: Bugfix for array insertion.
|
||||||
|
* Source/include/NSRunLoop.h: Remove limit ivar.
|
||||||
|
* Source/include/NSTimer.h: Use NSDate again.
|
||||||
|
|
||||||
Wed Apr 21 20:25:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
Wed Apr 21 20:25:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
* Source/NSAttributedString.m: Tidied.
|
* Source/NSAttributedString.m: Tidied.
|
||||||
|
|
|
@ -42,7 +42,6 @@ extern id NSDefaultRunLoopMode;
|
||||||
NSMutableArray *_timedPerformers;
|
NSMutableArray *_timedPerformers;
|
||||||
NSMapTable *_rfdMap;
|
NSMapTable *_rfdMap;
|
||||||
NSMapTable *_wfdMap;
|
NSMapTable *_wfdMap;
|
||||||
NSDate *_limit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSRunLoop*) currentRunLoop;
|
+ (NSRunLoop*) currentRunLoop;
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
*/
|
*/
|
||||||
@interface NSTimer : NSObject
|
@interface NSTimer : NSObject
|
||||||
{
|
{
|
||||||
NSTimeInterval _date; /* Must be first - for NSRunLoop optimisation */
|
NSDate *_date; /* Must be first - for NSRunLoop optimisation */
|
||||||
BOOL _invalidated; /* Must be 2nd - for NSRunLoop optimisation */
|
BOOL _invalidated; /* Must be 2nd - for NSRunLoop optimisation */
|
||||||
BOOL _repeats;
|
BOOL _repeats;
|
||||||
NSTimeInterval _interval;
|
NSTimeInterval _interval;
|
||||||
|
|
|
@ -46,8 +46,6 @@
|
||||||
|
|
||||||
static int debug_run_loop = 0;
|
static int debug_run_loop = 0;
|
||||||
static NSDate *theFuture = nil;
|
static NSDate *theFuture = nil;
|
||||||
static NSTimeInterval futureInterval;
|
|
||||||
static NSTimeInterval pastInterval;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,7 +87,7 @@ static SEL eventSel = @selector(receivedEvent:type:extra:forMode:);
|
||||||
@interface RunLoopWatcher: NSObject
|
@interface RunLoopWatcher: NSObject
|
||||||
{
|
{
|
||||||
@public
|
@public
|
||||||
NSTimeInterval _date; /* First to match layout of NSTimer */
|
NSDate *_date; /* First to match layout of NSTimer */
|
||||||
BOOL _invalidated; /* 2nd to match layout of NSTimer */
|
BOOL _invalidated; /* 2nd to match layout of NSTimer */
|
||||||
IMP handleEvent; /* New-style event handling */
|
IMP handleEvent; /* New-style event handling */
|
||||||
void *data;
|
void *data;
|
||||||
|
@ -106,6 +104,7 @@ static SEL eventSel = @selector(receivedEvent:type:extra:forMode:);
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
|
RELEASE(_date);
|
||||||
RELEASE(receiver);
|
RELEASE(receiver);
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
@ -141,7 +140,7 @@ static SEL eventSel = @selector(receivedEvent:type:extra:forMode:);
|
||||||
* the NSTimer class is known to be the same as RunLoopWatcher for the
|
* the NSTimer class is known to be the same as RunLoopWatcher for the
|
||||||
* first two elements.
|
* first two elements.
|
||||||
*/
|
*/
|
||||||
static inline NSTimeInterval timerDate(NSTimer* timer)
|
static inline NSDate* timerDate(NSTimer* timer)
|
||||||
{
|
{
|
||||||
return ((RunLoopWatcher*)timer)->_date;
|
return ((RunLoopWatcher*)timer)->_date;
|
||||||
}
|
}
|
||||||
|
@ -153,12 +152,7 @@ static inline BOOL timerInvalidated(NSTimer* timer)
|
||||||
|
|
||||||
static int aSort(RunLoopWatcher *i0, RunLoopWatcher *i1)
|
static int aSort(RunLoopWatcher *i0, RunLoopWatcher *i1)
|
||||||
{
|
{
|
||||||
if (i0->_date < i1->_date)
|
return [i0->_date compare: i1->_date];
|
||||||
return -1;
|
|
||||||
else if (i0->_date > i1->_date)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -430,7 +424,7 @@ static int aSort(RunLoopWatcher *i0, RunLoopWatcher *i1)
|
||||||
{
|
{
|
||||||
NSDate *d = [obj limitDateForMode: mode];
|
NSDate *d = [obj limitDateForMode: mode];
|
||||||
|
|
||||||
item->_date = [d timeIntervalSinceReferenceDate];
|
item->_date = RETAIN(d);
|
||||||
}
|
}
|
||||||
else if ([obj respondsToSelector: @selector(delegate)])
|
else if ([obj respondsToSelector: @selector(delegate)])
|
||||||
{
|
{
|
||||||
|
@ -439,13 +433,13 @@ static int aSort(RunLoopWatcher *i0, RunLoopWatcher *i1)
|
||||||
{
|
{
|
||||||
NSDate *d = [obj limitDateForMode: mode];
|
NSDate *d = [obj limitDateForMode: mode];
|
||||||
|
|
||||||
item->_date = [d timeIntervalSinceReferenceDate];
|
item->_date = RETAIN(d);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
item->_date = futureInterval;
|
item->_date = RETAIN(theFuture);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
item->_date = futureInterval;
|
item->_date = RETAIN(theFuture);
|
||||||
FastArrayInsertSorted(watchers, (FastArrayItem)item, aSort);
|
FastArrayInsertSorted(watchers, (FastArrayItem)item, aSort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -703,8 +697,6 @@ const NSMapTableValueCallBacks ArrayMapValueCallBacks =
|
||||||
{
|
{
|
||||||
[self currentRunLoop];
|
[self currentRunLoop];
|
||||||
theFuture = RETAIN([NSDate distantFuture]);
|
theFuture = RETAIN([NSDate distantFuture]);
|
||||||
futureInterval = [theFuture timeIntervalSinceReferenceDate];
|
|
||||||
pastInterval = [[NSDate distantPast] timeIntervalSinceReferenceDate];
|
|
||||||
#if GS_WITH_GC == 0
|
#if GS_WITH_GC == 0
|
||||||
wRelImp = [[RunLoopWatcher class] instanceMethodForSelector: wRelSel];
|
wRelImp = [[RunLoopWatcher class] instanceMethodForSelector: wRelSel];
|
||||||
wRetImp = [[RunLoopWatcher class] instanceMethodForSelector: wRetSel];
|
wRetImp = [[RunLoopWatcher class] instanceMethodForSelector: wRetSel];
|
||||||
|
@ -744,14 +736,12 @@ const NSMapTableValueCallBacks ArrayMapValueCallBacks =
|
||||||
WatcherMapValueCallBacks, 0);
|
WatcherMapValueCallBacks, 0);
|
||||||
_wfdMap = NSCreateMapTable (NSIntMapKeyCallBacks,
|
_wfdMap = NSCreateMapTable (NSIntMapKeyCallBacks,
|
||||||
WatcherMapValueCallBacks, 0);
|
WatcherMapValueCallBacks, 0);
|
||||||
_limit = RETAIN([NSDate date]);
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[self gcFinalize];
|
[self gcFinalize];
|
||||||
RELEASE(_limit);
|
|
||||||
RELEASE(_performers);
|
RELEASE(_performers);
|
||||||
RELEASE(_timedPerformers);
|
RELEASE(_timedPerformers);
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
|
@ -797,7 +787,7 @@ const NSMapTableValueCallBacks ArrayMapValueCallBacks =
|
||||||
- (NSDate*) limitDateForMode: (NSString*)mode
|
- (NSDate*) limitDateForMode: (NSString*)mode
|
||||||
{
|
{
|
||||||
id saved_mode;
|
id saved_mode;
|
||||||
NSTimeInterval when;
|
NSDate *when;
|
||||||
FastArray timers;
|
FastArray timers;
|
||||||
FastArray watchers;
|
FastArray watchers;
|
||||||
NSTimer *min_timer = nil;
|
NSTimer *min_timer = nil;
|
||||||
|
@ -819,7 +809,7 @@ const NSMapTableValueCallBacks ArrayMapValueCallBacks =
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timerDate(min_timer) > GSTimeNow())
|
if ([timerDate(min_timer) timeIntervalSinceNow] > 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -857,7 +847,7 @@ const NSMapTableValueCallBacks ArrayMapValueCallBacks =
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (min_watcher->_date > GSTimeNow())
|
if ([min_watcher->_date timeIntervalSinceNow] > 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -871,6 +861,7 @@ const NSMapTableValueCallBacks ArrayMapValueCallBacks =
|
||||||
* timeouts - inform it and give it a chance to set a
|
* timeouts - inform it and give it a chance to set a
|
||||||
* revised limit date.
|
* revised limit date.
|
||||||
*/
|
*/
|
||||||
|
FastArrayRemoveItemAtIndexNoRelease(watchers, 0);
|
||||||
obj = min_watcher->receiver;
|
obj = min_watcher->receiver;
|
||||||
if ([obj respondsToSelector:
|
if ([obj respondsToSelector:
|
||||||
@selector(timedOutEvent:type:forMode:)])
|
@selector(timedOutEvent:type:forMode:)])
|
||||||
|
@ -896,20 +887,18 @@ const NSMapTableValueCallBacks ArrayMapValueCallBacks =
|
||||||
* If the watcher has been given a revised limit date -
|
* If the watcher has been given a revised limit date -
|
||||||
* re-insert it into the queue in the correct place.
|
* re-insert it into the queue in the correct place.
|
||||||
*/
|
*/
|
||||||
FastArrayRemoveItemAtIndexNoRelease(watchers, 0);
|
ASSIGN(min_watcher->_date, nxt);
|
||||||
min_watcher->_date = [nxt timeIntervalSinceReferenceDate];
|
|
||||||
FastArrayInsertSortedNoRetain(watchers,
|
FastArrayInsertSortedNoRetain(watchers,
|
||||||
(FastArrayItem)min_watcher, aSort);
|
(FastArrayItem)min_watcher, aSort);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* If the watcher is now useless - invalidate it and
|
* If the watcher is now useless - invalidate and
|
||||||
* remove it from the queue so that we don't need to
|
* release it.
|
||||||
* check it again.
|
|
||||||
*/
|
*/
|
||||||
min_watcher->_invalidated = YES;
|
min_watcher->_invalidated = YES;
|
||||||
FastArrayRemoveItemAtIndex(watchers, 0);
|
RELEASE(min_watcher);
|
||||||
}
|
}
|
||||||
min_watcher = nil;
|
min_watcher = nil;
|
||||||
}
|
}
|
||||||
|
@ -927,7 +916,8 @@ const NSMapTableValueCallBacks ArrayMapValueCallBacks =
|
||||||
if (min_timer)
|
if (min_timer)
|
||||||
{
|
{
|
||||||
when = timerDate(min_timer);
|
when = timerDate(min_timer);
|
||||||
if (min_watcher && min_watcher->_date < when)
|
if (min_watcher != nil
|
||||||
|
&& [min_watcher->_date compare: when] == NSOrderedAscending)
|
||||||
{
|
{
|
||||||
when = min_watcher->_date;
|
when = min_watcher->_date;
|
||||||
}
|
}
|
||||||
|
@ -943,11 +933,11 @@ const NSMapTableValueCallBacks ArrayMapValueCallBacks =
|
||||||
|
|
||||||
if (debug_run_loop)
|
if (debug_run_loop)
|
||||||
{
|
{
|
||||||
printf ("\tNSRunLoop limit date %f\n", when);
|
printf ("\tNSRunLoop limit date %f\n",
|
||||||
|
[when timeIntervalSinceReferenceDate]);
|
||||||
}
|
}
|
||||||
|
|
||||||
_limit = [_limit initWithTimeIntervalSinceReferenceDate: when];
|
return when;
|
||||||
return _limit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (RunLoopWatcher*) _getWatcher: (void*)data
|
- (RunLoopWatcher*) _getWatcher: (void*)data
|
||||||
|
@ -1270,6 +1260,7 @@ const NSMapTableValueCallBacks ArrayMapValueCallBacks =
|
||||||
{
|
{
|
||||||
id d;
|
id d;
|
||||||
|
|
||||||
|
NSAssert(mode && date, NSInvalidArgumentException);
|
||||||
/* If date has already passed, simply return. */
|
/* If date has already passed, simply return. */
|
||||||
if ([date timeIntervalSinceNow] < 0)
|
if ([date timeIntervalSinceNow] < 0)
|
||||||
{
|
{
|
||||||
|
@ -1294,18 +1285,13 @@ const NSMapTableValueCallBacks ArrayMapValueCallBacks =
|
||||||
/* Use the earlier of the two dates we have. */
|
/* Use the earlier of the two dates we have. */
|
||||||
d = [d earlierDate: date];
|
d = [d earlierDate: date];
|
||||||
|
|
||||||
/*
|
RETAIN(d);
|
||||||
* If the date is not our own ivar, we must retain it so it doesn't
|
|
||||||
* get destroyed inside the run loop
|
|
||||||
*/
|
|
||||||
if (d != _limit)
|
|
||||||
RETAIN(d);
|
|
||||||
|
|
||||||
/* Wait, listening to our input sources. */
|
/* Wait, listening to our input sources. */
|
||||||
[self acceptInputForMode: mode beforeDate: d];
|
[self acceptInputForMode: mode beforeDate: d];
|
||||||
|
|
||||||
if (d != _limit)
|
RELEASE(d);
|
||||||
RELEASE(d);
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,11 @@
|
||||||
userInfo: info
|
userInfo: info
|
||||||
repeats: (BOOL)f
|
repeats: (BOOL)f
|
||||||
{
|
{
|
||||||
|
if (seconds <= 0)
|
||||||
|
seconds = 1;
|
||||||
_interval = seconds;
|
_interval = seconds;
|
||||||
_date = GSTimeNow() + seconds;
|
_date = [[NSDate allocWithZone: [self zone]]
|
||||||
|
initWithTimeIntervalSinceNow: seconds];
|
||||||
_target = t;
|
_target = t;
|
||||||
_selector = sel;
|
_selector = sel;
|
||||||
_info = info;
|
_info = info;
|
||||||
|
@ -96,6 +99,11 @@
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
RELEASE(_date);
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) fire
|
- (void) fire
|
||||||
{
|
{
|
||||||
|
@ -109,17 +117,21 @@
|
||||||
else if (!_invalidated)
|
else if (!_invalidated)
|
||||||
{
|
{
|
||||||
NSTimeInterval now = GSTimeNow();
|
NSTimeInterval now = GSTimeNow();
|
||||||
|
NSTimeInterval nxt = [_date timeIntervalSinceReferenceDate];
|
||||||
int inc = -1;
|
int inc = -1;
|
||||||
|
|
||||||
while (_date <= now) // xxx remove this
|
while (nxt <= now) // xxx remove this
|
||||||
{
|
{
|
||||||
inc++;
|
inc++;
|
||||||
_date += _interval;
|
nxt += _interval;
|
||||||
}
|
}
|
||||||
#ifdef LOG_MISSED
|
#ifdef LOG_MISSED
|
||||||
if (inc > 0)
|
if (inc > 0)
|
||||||
NSLog(@"Missed %d timeouts at %f second intervals", inc, _interval);
|
NSLog(@"Missed %d timeouts at %f second intervals", inc, _interval);
|
||||||
#endif
|
#endif
|
||||||
|
RELEASE(_date);
|
||||||
|
_date = [[NSDate allocWithZone: [self zone]]
|
||||||
|
initWithTimeIntervalSinceReferenceDate: nxt];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +148,7 @@
|
||||||
|
|
||||||
- fireDate
|
- fireDate
|
||||||
{
|
{
|
||||||
return [NSDate dateWithTimeIntervalSinceReferenceDate: _date];
|
return _date;
|
||||||
}
|
}
|
||||||
|
|
||||||
- userInfo
|
- userInfo
|
||||||
|
@ -144,13 +156,9 @@
|
||||||
return _info;
|
return _info;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int) compare: (NSTimer*)anotherTimer
|
- (NSComparisonResult) compare: (NSTimer*)anotherTimer
|
||||||
{
|
{
|
||||||
if (_date < anotherTimer->_date)
|
return [_date compare: anotherTimer->_date];
|
||||||
return NSOrderedAscending;
|
|
||||||
else if (_date > anotherTimer->_date)
|
|
||||||
return NSOrderedDescending;
|
|
||||||
else
|
|
||||||
return NSOrderedSame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue