Author: rfm
Date: Wed May  6 12:42:00 2015
New Revision: 38479

URL: http://svn.gna.org/viewcvs/gnustep?rev=38479&view=rev
Log:
optimise removal of a range of objects from an array

Modified:
    libs/base/trunk/Source/GSArray.m

Modified: libs/base/trunk/Source/GSArray.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/GSArray.m?rev=38479&r1=38478&r2=38479&view=diff
==============================================================================
--- libs/base/trunk/Source/GSArray.m    (original)
+++ libs/base/trunk/Source/GSArray.m    Wed May  6 12:42:00 2015
@@ -787,6 +787,60 @@
        }
     }
   _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


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to