mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +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
be83e93eb9
commit
cefb7048ac
3 changed files with 35 additions and 27 deletions
|
@ -1,9 +1,9 @@
|
||||||
1999-04-28 Adam Fedor <fedor@gnu.org>
|
1999-04-28 Adam Fedor <fedor@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSRunLoop.m (aSort): Redefine to take FastArrayItem as
|
||||||
|
arguments.
|
||||||
* Source/include/FastArray.x (FastArrayInsertionPosition):
|
* Source/include/FastArray.x (FastArrayInsertionPosition):
|
||||||
'Dereference' union object value (on PPC's at least, the union
|
Fully specify sorter function for better type checking.
|
||||||
address may not be the same as the address of the first type in
|
|
||||||
the union).
|
|
||||||
(FastArrayCheckSort): Likewise.
|
(FastArrayCheckSort): Likewise.
|
||||||
|
|
||||||
1999-04-27 Adam Fedor <fedor@gnu.org>
|
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
|
* 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.
|
* 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 function should return NSOrderedAscending if the item to be
|
||||||
* the item in the array, >0 if it is greater, and 0 if it is equal.
|
* added is 'less than' the item in the array, NSOrderedDescending
|
||||||
|
* if it is greater, and NSOrderedSame if it is equal.
|
||||||
*/
|
*/
|
||||||
static INLINE unsigned
|
static INLINE unsigned
|
||||||
FastArrayInsertionPosition(FastArray array, FastArrayItem item, int (*sorter)())
|
FastArrayInsertionPosition(FastArray array, FastArrayItem item,
|
||||||
|
NSComparisonResult (*sorter)(FastArrayItem, FastArrayItem))
|
||||||
{
|
{
|
||||||
unsigned upper = array->count;
|
unsigned upper = array->count;
|
||||||
unsigned lower = 0;
|
unsigned lower = 0;
|
||||||
|
@ -224,26 +226,28 @@ FastArrayInsertionPosition(FastArray array, FastArrayItem item, int (*sorter)())
|
||||||
*/
|
*/
|
||||||
for (index = upper/2; upper != lower; index = lower+(upper-lower)/2)
|
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;
|
{
|
||||||
|
upper = index;
|
||||||
}
|
}
|
||||||
else if (comparison > 0)
|
else if (comparison == NSOrderedDescending)
|
||||||
{
|
{
|
||||||
lower = index + 1;
|
lower = index + 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Now skip past any equal items so the insertion point is AFTER any
|
* Now skip past any equal items so the insertion point is AFTER any
|
||||||
* items that are equal to the new one.
|
* 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++;
|
index++;
|
||||||
}
|
}
|
||||||
|
@ -253,20 +257,22 @@ FastArrayInsertionPosition(FastArray array, FastArrayItem item, int (*sorter)())
|
||||||
|
|
||||||
#ifndef NS_BLOCK_ASSERTIONS
|
#ifndef NS_BLOCK_ASSERTIONS
|
||||||
static INLINE void
|
static INLINE void
|
||||||
FastArrayCheckSort(FastArray array, int (*sorter)())
|
FastArrayCheckSort(FastArray array,
|
||||||
|
NSComparisonResult (*sorter)(FastArrayItem, FastArrayItem))
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
for (i = 1; i < array->count; i++)
|
for (i = 1; i < array->count; i++)
|
||||||
{
|
{
|
||||||
NSCAssert(((*sorter)((array->ptr[i-1]).obj, (array->ptr[i]).obj) <= 0),
|
NSCAssert(((*sorter)(array->ptr[i-1], array->ptr[i])
|
||||||
NSInvalidArgumentException);
|
!= NSOrderedDecending), NSInvalidArgumentException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static INLINE void
|
static INLINE void
|
||||||
FastArrayInsertSorted(FastArray array, FastArrayItem item, int (*sorter)())
|
FastArrayInsertSorted(FastArray array, FastArrayItem item,
|
||||||
|
NSComparisonResult (*sorter)(FastArrayItem, FastArrayItem))
|
||||||
{
|
{
|
||||||
unsigned index;
|
unsigned index;
|
||||||
|
|
||||||
|
@ -278,7 +284,8 @@ FastArrayInsertSorted(FastArray array, FastArrayItem item, int (*sorter)())
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE void
|
static INLINE void
|
||||||
FastArrayInsertSortedNoRetain(FastArray array, FastArrayItem item, int (*sorter)())
|
FastArrayInsertSortedNoRetain(FastArray array, FastArrayItem item,
|
||||||
|
NSComparisonResult (*sorter)(FastArrayItem, FastArrayItem))
|
||||||
{
|
{
|
||||||
unsigned index;
|
unsigned index;
|
||||||
|
|
||||||
|
|
|
@ -150,11 +150,6 @@ static inline BOOL timerInvalidated(NSTimer* timer)
|
||||||
return ((RunLoopWatcher*)timer)->_invalidated;
|
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>
|
#include <base/FastArray.x>
|
||||||
|
|
||||||
|
static NSComparisonResult aSort(FastArrayItem i0, FastArrayItem i1)
|
||||||
|
{
|
||||||
|
return [((RunLoopWatcher *)(i0.obj))->_date
|
||||||
|
compare: ((RunLoopWatcher *)(i1.obj))->_date];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@interface NSRunLoop (TimedPerformers)
|
@interface NSRunLoop (TimedPerformers)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue