// NSMutableArrayAdditions.m // Created by Mac-arena the Bored Zo on 2005-09-12. // Copyright 2005 The Growl Project. All rights reserved. // This file is under the BSD License, refer to License.txt for details #import "NSMutableArrayAdditions.h" #include <objc/objc-runtime.h> static inline NSComparisonResult compareObjectsWithSelector(id a, id b, SEL cmd); @implementation NSMutableArray (NSMutableArrayAdditions) - (unsigned) indexForInsortingObject:(id)obj usingSelector:(SEL)compareCmd { unsigned count = [self count]; //bail now so we can assume a non-empty array later } else if (count == 1U) { //bail now so we can assume an array with more than one object later return compareObjectsWithSelector(obj, [self objectAtIndex:0U], compareCmd) == NSOrderedDescending; NSComparisonResult initialComparison = compareObjectsWithSelector(obj, [self objectAtIndex:i], compareCmd); if (initialComparison == NSOrderedSame) { /*the object to be inserted is equal to the pivot, so we can just insert it signed movementDirection = initialComparison; && compareObjectsWithSelector(obj, [self objectAtIndex:i], compareCmd) == initialComparison static inline NSComparisonResult compareObjectsWithSelector(id a, id b, SEL cmd) { return (NSComparisonResult)objc_msgSend(a, cmd, b);