From 433dd8ef66d498d2020d23199f18b67c49ded9d9 Mon Sep 17 00:00:00 2001 From: Andrew McCallum Date: Sat, 30 Mar 1996 19:04:35 +0000 Subject: [PATCH] ([IndexedCollection -removeObject:]): Now removes *all* instances of ANOBJECT, not just one. ([IndexedCollection -replaceObject:withObject:]): Now replaces *all* instances of OLDOBJECT, not just one. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1303 72102866-910b-0410-8b05-ffd578937521 --- Source/IndexedCollection.m | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/Source/IndexedCollection.m b/Source/IndexedCollection.m index 7d0319b65..8861af153 100644 --- a/Source/IndexedCollection.m +++ b/Source/IndexedCollection.m @@ -428,15 +428,36 @@ - (void) removeObject: anObject { - int index = [self indexOfObject: anObject]; - if (index != NO_INDEX) + int index; + + /* Retain the object. Yuck, but necessary in case the array holds + the last reference to anObject. */ + /* xxx Is there an alternative to this expensive retain/release? */ + [anObject retain]; + + for (index = [self indexOfObject: anObject]; + index != NO_INDEX; + index = [self indexOfObject: anObject]) [self removeObjectAtIndex: index]; + + [anObject release]; } - (void) replaceObject: oldObject withObject: newObject { - int i = [self indexOfObject: oldObject]; - [self replaceObjectAtIndex: i withObject: newObject]; + int index; + + /* Retain the object. Yuck, but necessary in case the array holds + the last reference to anObject. */ + /* xxx Is there an alternative to this expensive retain/release? */ + [oldObject retain]; + + for (index = [self indexOfObject: oldObject]; + index != NO_INDEX; + index = [self indexOfObject: oldObject]) + [self replaceObjectAtIndex: index withObject: newObject]; + + [oldObject release]; } @end