mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
Better fix from Richard.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4160 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
f987369adc
commit
d2c443b68b
3 changed files with 35 additions and 27 deletions
|
@ -1,9 +1,9 @@
|
|||
1999-04-28 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Source/NSRunLoop.m (aSort): Redefine to take FastArrayItem as
|
||||
arguments.
|
||||
* Source/include/FastArray.x (FastArrayInsertionPosition):
|
||||
'Dereference' union object value (on PPC's at least, the union
|
||||
address may not be the same as the address of the first type in
|
||||
the union).
|
||||
Fully specify sorter function for better type checking.
|
||||
(FastArrayCheckSort): Likewise.
|
||||
|
||||
1999-04-27 Adam Fedor <fedor@gnu.org>
|
||||
|
|
|
@ -209,11 +209,13 @@ FastArrayAddItemNoRetain(FastArray array, FastArrayItem item)
|
|||
/*
|
||||
* The comparator function takes two items as arguments, the first is the
|
||||
* item to be added, the second is the item already in the array.
|
||||
* The function should return <0 if the item to be added is 'less than'
|
||||
* the item in the array, >0 if it is greater, and 0 if it is equal.
|
||||
* The function should return NSOrderedAscending if the item to be
|
||||
* added is 'less than' the item in the array, NSOrderedDescending
|
||||
* if it is greater, and NSOrderedSame if it is equal.
|
||||
*/
|
||||
static INLINE unsigned
|
||||
FastArrayInsertionPosition(FastArray array, FastArrayItem item, int (*sorter)())
|
||||
FastArrayInsertionPosition(FastArray array, FastArrayItem item,
|
||||
NSComparisonResult (*sorter)(FastArrayItem, FastArrayItem))
|
||||
{
|
||||
unsigned upper = array->count;
|
||||
unsigned lower = 0;
|
||||
|
@ -224,13 +226,14 @@ FastArrayInsertionPosition(FastArray array, FastArrayItem item, int (*sorter)())
|
|||
*/
|
||||
for (index = upper/2; upper != lower; index = lower+(upper-lower)/2)
|
||||
{
|
||||
int comparison = (*sorter)(item.obj, (array->ptr[index]).obj);
|
||||
NSComparisonResult comparison;
|
||||
|
||||
if (comparison < 0)
|
||||
comparison = (*sorter)(item, (array->ptr[index]));
|
||||
if (comparison == NSOrderedAscending)
|
||||
{
|
||||
upper = index;
|
||||
}
|
||||
else if (comparison > 0)
|
||||
else if (comparison == NSOrderedDescending)
|
||||
{
|
||||
lower = index + 1;
|
||||
}
|
||||
|
@ -243,7 +246,8 @@ FastArrayInsertionPosition(FastArray array, FastArrayItem item, int (*sorter)())
|
|||
* Now skip past any equal items so the insertion point is AFTER any
|
||||
* items that are equal to the new one.
|
||||
*/
|
||||
while (index < array->count && (*sorter)(item.obj, (array->ptr[index]).obj) >= 0)
|
||||
while (index < array->count
|
||||
&& (*sorter)(item, (array->ptr[index])) != NSOrderedAscending)
|
||||
{
|
||||
index++;
|
||||
}
|
||||
|
@ -253,20 +257,22 @@ FastArrayInsertionPosition(FastArray array, FastArrayItem item, int (*sorter)())
|
|||
|
||||
#ifndef NS_BLOCK_ASSERTIONS
|
||||
static INLINE void
|
||||
FastArrayCheckSort(FastArray array, int (*sorter)())
|
||||
FastArrayCheckSort(FastArray array,
|
||||
NSComparisonResult (*sorter)(FastArrayItem, FastArrayItem))
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 1; i < array->count; i++)
|
||||
{
|
||||
NSCAssert(((*sorter)((array->ptr[i-1]).obj, (array->ptr[i]).obj) <= 0),
|
||||
NSInvalidArgumentException);
|
||||
NSCAssert(((*sorter)(array->ptr[i-1], array->ptr[i])
|
||||
!= NSOrderedDecending), NSInvalidArgumentException);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static INLINE void
|
||||
FastArrayInsertSorted(FastArray array, FastArrayItem item, int (*sorter)())
|
||||
FastArrayInsertSorted(FastArray array, FastArrayItem item,
|
||||
NSComparisonResult (*sorter)(FastArrayItem, FastArrayItem))
|
||||
{
|
||||
unsigned index;
|
||||
|
||||
|
@ -278,7 +284,8 @@ FastArrayInsertSorted(FastArray array, FastArrayItem item, int (*sorter)())
|
|||
}
|
||||
|
||||
static INLINE void
|
||||
FastArrayInsertSortedNoRetain(FastArray array, FastArrayItem item, int (*sorter)())
|
||||
FastArrayInsertSortedNoRetain(FastArray array, FastArrayItem item,
|
||||
NSComparisonResult (*sorter)(FastArrayItem, FastArrayItem))
|
||||
{
|
||||
unsigned index;
|
||||
|
||||
|
|
|
@ -150,11 +150,6 @@ static inline BOOL timerInvalidated(NSTimer* timer)
|
|||
return ((RunLoopWatcher*)timer)->_invalidated;
|
||||
}
|
||||
|
||||
static int aSort(RunLoopWatcher *i0, RunLoopWatcher *i1)
|
||||
{
|
||||
return [i0->_date compare: i1->_date];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
@ -173,6 +168,12 @@ static int aSort(RunLoopWatcher *i0, RunLoopWatcher *i1)
|
|||
|
||||
#include <base/FastArray.x>
|
||||
|
||||
static NSComparisonResult aSort(FastArrayItem i0, FastArrayItem i1)
|
||||
{
|
||||
return [((RunLoopWatcher *)(i0.obj))->_date
|
||||
compare: ((RunLoopWatcher *)(i1.obj))->_date];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@interface NSRunLoop (TimedPerformers)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue