mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-01 09:02:01 +00:00
([ConstantIndexedCollection -firstObject]): Return nil if emtpy.
([ConstantIndexedCollection -lastObject]): Likewise. ([ConstantIndexedCollection -prevObjectWithEnumState:]): Use -1 to deal with reversals at extremes. ([ConstantIndexedCollection -nextObjectWithEnumState:]): Use [self count] to deal with reversals at extremes. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1132 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3e003b0db1
commit
88cb4347f5
1 changed files with 16 additions and 5 deletions
|
@ -51,11 +51,15 @@
|
||||||
|
|
||||||
- firstObject
|
- firstObject
|
||||||
{
|
{
|
||||||
|
if ([self isEmpty])
|
||||||
|
return nil;
|
||||||
return [self objectAtIndex: 0];
|
return [self objectAtIndex: 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
- lastObject
|
- lastObject
|
||||||
{
|
{
|
||||||
|
if ([self isEmpty])
|
||||||
|
return nil;
|
||||||
return [self objectAtIndex: [self count]-1];
|
return [self objectAtIndex: [self count]-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,15 +276,19 @@
|
||||||
|
|
||||||
/* If there are not objects in this collection, or we are being
|
/* If there are not objects in this collection, or we are being
|
||||||
asked for the object before the first object, return nil. */
|
asked for the object before the first object, return nil. */
|
||||||
if ([self isEmpty] || (*(int*)enumState) == 0)
|
if ([self isEmpty] || ((*(int*)enumState) == 0)
|
||||||
return NO_OBJECT;
|
|| ((*(int*)enumState) == -1))
|
||||||
|
{
|
||||||
|
(*(int*)enumState) == -1;
|
||||||
|
return NO_OBJECT;
|
||||||
|
}
|
||||||
|
|
||||||
if (*(int*)enumState == -2)
|
if (*(int*)enumState == -2)
|
||||||
/* enumState was just initialized by -newEnumState, start
|
/* enumState was just initialized by -newEnumState, start
|
||||||
at the end of the sequence. */
|
at the end of the sequence. */
|
||||||
*(int*)enumState = [self count]-1;
|
*(int*)enumState = [self count]-1;
|
||||||
else
|
else
|
||||||
/* ...otherwise go to the previous index.*/
|
/* ...otherwise go the previous index. */
|
||||||
(*(int*)enumState)--;
|
(*(int*)enumState)--;
|
||||||
|
|
||||||
return [self objectAtIndex:(*(unsigned*)enumState)];
|
return [self objectAtIndex:(*(unsigned*)enumState)];
|
||||||
|
@ -325,8 +333,11 @@
|
||||||
|
|
||||||
/* If there are not objects in this collection, or we are being
|
/* If there are not objects in this collection, or we are being
|
||||||
asked for the object after the last object, return nil. */
|
asked for the object after the last object, return nil. */
|
||||||
if ([self isEmpty] || (*(int*)enumState) > [self count]-1)
|
if ([self isEmpty] || ((*(int*)enumState) >= (int)([self count]-1)))
|
||||||
return NO_OBJECT;
|
{
|
||||||
|
(*(int*)enumState) = [self count];
|
||||||
|
return NO_OBJECT;
|
||||||
|
}
|
||||||
|
|
||||||
if (*(int*)enumState == -2)
|
if (*(int*)enumState == -2)
|
||||||
/* enumState was just initialized by -newEnumState, start
|
/* enumState was just initialized by -newEnumState, start
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue