Do retain/release/autorelease of contents as appropriate.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@129 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Andrew McCallum 1995-03-15 23:36:56 +00:00
parent 2f2c73398e
commit 36314e2ab0
2 changed files with 13 additions and 3 deletions

View file

@ -195,6 +195,7 @@
- appendElement: (elt)newElement - appendElement: (elt)newElement
{ {
incrementCount(self); incrementCount(self);
RETAIN_ELT(newElement);
_contents_array[_count-1] = newElement; _contents_array[_count-1] = newElement;
return self; return self;
} }
@ -202,6 +203,7 @@
- prependElement: (elt)newElement - prependElement: (elt)newElement
{ {
incrementCount(self); incrementCount(self);
RETAIN_ELT(newElement);
makeHoleAt(self, 0); makeHoleAt(self, 0);
_contents_array[0] = newElement; _contents_array[0] = newElement;
return self; return self;
@ -211,6 +213,7 @@
{ {
CHECK_INDEX_RANGE_ERROR(index, _count+1); CHECK_INDEX_RANGE_ERROR(index, _count+1);
incrementCount(self); incrementCount(self);
RETAIN_ELT(newElement);
makeHoleAt(self, index); makeHoleAt(self, index);
_contents_array[index] = newElement; _contents_array[index] = newElement;
return self; return self;
@ -227,7 +230,7 @@
ret = _contents_array[index]; ret = _contents_array[index];
fillHoleAt(self, index); fillHoleAt(self, index);
decrementCount(self); decrementCount(self);
return ret; return AUTORELEASE_ELT(ret);
} }
/* We could be more efficient if we override these also. /* We could be more efficient if we override these also.
@ -240,9 +243,10 @@
elt ret; elt ret;
CHECK_INDEX_RANGE_ERROR(index, _count); CHECK_INDEX_RANGE_ERROR(index, _count);
RETAIN_ELT(newElement);
ret = _contents_array[index]; ret = _contents_array[index];
_contents_array[index] = newElement; _contents_array[index] = newElement;
return ret; return AUTORELEASE_ELT(ret);
} }
- swapAtIndeces: (unsigned)index1 : (unsigned)index2 - swapAtIndeces: (unsigned)index1 : (unsigned)index2

View file

@ -81,6 +81,8 @@
else else
coll_hash_add(&_contents_hash, newElement, count); coll_hash_add(&_contents_hash, newElement, count);
_count += count; _count += count;
while (count--)
RETAIN_ELT(newElement);
return self; return self;
} }
@ -120,7 +122,9 @@
coll_hash_remove(_contents_hash, oldElement); coll_hash_remove(_contents_hash, oldElement);
} }
_count -= count; _count -= count;
return oldElement; while (count-- > 0)
RELEASE_ELT(oldElement);
return AUTORELEASE_ELT(oldElement);
} }
- (elt) removeElement: (elt)oldElement ifAbsentCall: (elt(*)(arglist_t))excFunc - (elt) removeElement: (elt)oldElement ifAbsentCall: (elt(*)(arglist_t))excFunc
@ -136,6 +140,8 @@
_count = 0; _count = 0;
while ((node = coll_hash_next(_contents_hash, &state))) while ((node = coll_hash_next(_contents_hash, &state)))
{ {
while ((node->value.unsigned_int_u)-- > 0)
RELEASE_ELT(node->key);
node->value.unsigned_int_u = 1; node->value.unsigned_int_u = 1;
_count++; _count++;
} }