From c720626d76c94bdc043a8f1b8536c7a319ddeaa8 Mon Sep 17 00:00:00 2001 From: rfm Date: Sun, 13 Aug 2006 09:17:53 +0000 Subject: [PATCH] Fixups for macos-x compatibility git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@23271 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 2 +- Headers/Foundation/NSIndexPath.h | 3 ++- Source/NSIndexPath.m | 43 +++++++++++++++++--------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index f9692017d..5086fce11 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,7 +4,7 @@ multibyte encodings) strings could be truncated at the wrong precision. * Source/NSIndexPath.m: ([indexAtPosition:]) return NSNotFound if - given a bad position. + given a bad position. ([compare:]) fix to match MacOS-X * Source/NSObject.m: implement CRASH_ON_ZOMBIE * Documentation/Base.gsdoc: document it. diff --git a/Headers/Foundation/NSIndexPath.h b/Headers/Foundation/NSIndexPath.h index 99b4887d5..54bf03580 100644 --- a/Headers/Foundation/NSIndexPath.h +++ b/Headers/Foundation/NSIndexPath.h @@ -69,7 +69,8 @@ - (void) getIndexes: (unsigned*)aBuffer; /** - * Return the index at the specified position or raise an exception. + * Return the index at the specified position or NSNotFound if there + * is no index at the specified position. */ - (unsigned) indexAtPosition: (unsigned)position; diff --git a/Source/NSIndexPath.m b/Source/NSIndexPath.m index d13009f2f..f739b011c 100644 --- a/Source/NSIndexPath.m +++ b/Source/NSIndexPath.m @@ -78,35 +78,38 @@ static NSIndexPath *dummy = nil; - (NSComparisonResult) compare: (NSIndexPath*)other { - if (other == self) - { - return NSOrderedSame; - } - else + if (other != self) { + unsigned olength = other->_length; + unsigned *oindexes = other->_indexes; + unsigned end = (_length > olength) ? _length : olength; unsigned pos; - for (pos = 0; pos < _length; pos++) + for (pos = 0; pos < end; pos++) { - if (pos >= other->_length || other->_indexes[pos] < _indexes[pos]) - { - return NSOrderedAscending; - } - if (other->_indexes[pos] > _indexes[pos]) + if (pos >= _length) { return NSOrderedDescending; } + else if (pos >= olength) + { + return NSOrderedAscending; + } + if (oindexes[pos] < _indexes[pos]) + { + return NSOrderedDescending; + } + if (oindexes[pos] > _indexes[pos]) + { + return NSOrderedAscending; + } } - if (_length == other->_length) - { - /* - * Should never get here. - */ - NSLog(@"Argh ... two identical index paths exist!"); - return NSOrderedSame; - } - return NSOrderedDescending; + /* + * Should never get here. + */ + NSLog(@"Argh ... two identical index paths exist!"); } + return NSOrderedSame; } - (id) copyWithZone: (NSZone*)aZone