mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
optimise removal of a range of objects from an array
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38479 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ce991d339a
commit
d789edd709
1 changed files with 54 additions and 0 deletions
|
@ -789,6 +789,60 @@ static Class GSInlineArrayClass;
|
|||
_version++;
|
||||
}
|
||||
|
||||
- (void) removeObjectsInRange: (NSRange)aRange
|
||||
{
|
||||
GS_RANGE_CHECK(aRange, _count);
|
||||
|
||||
if (aRange.length > 0)
|
||||
{
|
||||
NSUInteger index;
|
||||
NSUInteger tail;
|
||||
NSUInteger end;
|
||||
#if GS_WITH_GC == 0
|
||||
IMP rel = 0;
|
||||
Class last = Nil;
|
||||
#endif
|
||||
|
||||
_version++;
|
||||
index = aRange.location;
|
||||
|
||||
#if GS_WITH_GC == 0
|
||||
/* Release all the objects we are removing.
|
||||
*/
|
||||
end = NSMaxRange(aRange);
|
||||
while (end-- > index)
|
||||
{
|
||||
id o = _contents_array[end];
|
||||
Class c = object_getClass(o);
|
||||
|
||||
if (c != last)
|
||||
{
|
||||
last = c;
|
||||
rel = [o methodForSelector: @selector(release)];
|
||||
}
|
||||
(*rel)(o, @selector(release));
|
||||
_contents_array[end] = nil;
|
||||
}
|
||||
#endif
|
||||
/* Move any trailing objects to fill the hole we made.
|
||||
*/
|
||||
end = NSMaxRange(aRange);
|
||||
tail = _count - end;
|
||||
if (tail > 0)
|
||||
{
|
||||
memmove(_contents_array + index, _contents_array + end,
|
||||
tail * sizeof(id));
|
||||
index += tail;
|
||||
}
|
||||
_count = index;
|
||||
|
||||
/* Clear emptied part of buffer.
|
||||
*/
|
||||
memset(_contents_array + _count, 0, aRange.length * sizeof(id));
|
||||
_version++;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) replaceObjectAtIndex: (NSUInteger)index withObject: (id)anObject
|
||||
{
|
||||
id obj;
|
||||
|
|
Loading…
Reference in a new issue