Fix a number of comments by Fred

This commit is contained in:
Gregory John Casamento 2019-06-10 10:20:26 -04:00
parent d8030311d0
commit 966c31f43d
4 changed files with 77 additions and 80 deletions

View file

@ -212,13 +212,6 @@ static Class mutableSetClass;
{
NSUInteger i = 0;
// Reduce C if it doesn't match. This is apparently how
// macOS behaves.
if(c > sizeof(objs))
{
c = sizeof(objs);
}
// Initialize and fill the set.
GSIArrayInitWithZoneAndCapacity(&array, [self zone], c);
for (i = 0; i < c; i++)
@ -321,20 +314,13 @@ static Class mutableSetClass;
{
NSUInteger i = 0;
// Reduce count if more then size of list of objects
if(sizeof(objects) < count)
{
count = sizeof(objects);
}
// Init and fill set
self = [self initWithCapacity: count];
if(self != nil)
{
for(i = 0; i < count; i++)
{
id anObject = objects[i];
id anObject = objects[i];
if (anObject == nil)
{
NSLog(@"Tried to init an orderedset with a nil object");

View file

@ -949,14 +949,17 @@ compareIt(id o1, id o2, void* context)
return k;
}
- (NSArray *)keysSortedByValueUsingComparator:(NSComparator)cmptr
- (NSArray *)keysSortedByValueUsingComparator: (NSComparator)cmptr
{
return [self keysSortedByValueWithOptions:0 usingComparator:cmptr];
return [self keysSortedByValueWithOptions:0
usingComparator:cmptr];
}
- (NSArray *)keysSortedByValueWithOptions:(NSSortOptions)opts usingComparator:(NSComparator)cmptr
- (NSArray *)keysSortedByValueWithOptions: (NSSortOptions)opts
usingComparator: (NSComparator)cmptr
{
return [[self allKeys] sortedArrayWithOptions: opts usingComparator: cmptr];
return [[self allKeys] sortedArrayWithOptions: opts
usingComparator: cmptr];
}
/**

View file

@ -105,6 +105,7 @@ static SEL rlSel;
// NSCoding
- (instancetype) initWithCoder: (NSCoder *)coder
{
/*
Class c;
c = object_getClass(self);
@ -114,13 +115,13 @@ static SEL rlSel;
self = [NSOrderedSet_concrete_class allocWithZone: NSDefaultMallocZone()];
return [self initWithCoder: coder];
}
else if (c == NSOrderedSet_abstract_class)
else if (c == NSMutableOrderedSet_abstract_class)
{
DESTROY(self);
self = [NSOrderedSet_concrete_class allocWithZone: NSDefaultMallocZone()];
self = [NSMutableOrderedSet_concrete_class allocWithZone: NSDefaultMallocZone()];
return [self initWithCoder: coder];
}
*/
if ([coder allowsKeyedCoding])
{
id array;
@ -396,7 +397,14 @@ static SEL rlSel;
for (i = 0; i < count; i++)
{
objs[i] = [other objectAtIndex: i];
if (flag == NO)
{
objs[i] = [other objectAtIndex: i];
}
else // copy the items.
{
objs[i] = [[other objectAtIndex: i] copy];
}
}
}
else
@ -423,38 +431,34 @@ static SEL rlSel;
{
GS_BEGINIDBUF(objs, count);
if ([other isProxy])
{
unsigned i = 0;
unsigned loc = range.location;
unsigned len = range.length;
unsigned j = 0;
for (i = 0; i < count; i++)
{
if(i >= loc && j < len)
{
if(flag == YES)
{
objs[i] = [[other objectAtIndex: i] copy];
}
else
{
objs[i] = [other objectAtIndex: i];
}
j++;
}
if(j >= len)
{
break;
}
}
}
else
{
[other getObjects: objs];
}
{
unsigned i = 0;
unsigned loc = range.location;
unsigned len = range.length;
unsigned j = 0;
for (i = 0; i < count; i++)
{
if(i >= loc && j < len)
{
if(flag == YES)
{
objs[i] = [[other objectAtIndex: i] copy];
}
else
{
objs[i] = [other objectAtIndex: i];
}
j++;
}
if(j >= len)
{
break;
}
}
}
self = [self initWithObjects: objs count: count];
GS_ENDIDBUF();
return self;
@ -995,7 +999,7 @@ static SEL rlSel;
- (id) valueForKey: (NSString*)key
{
NSEnumerator *e = [self objectEnumerator];
NSEnumerator *e = [self objectEnumerator];
id object = nil;
NSMutableSet *results = [NSMutableSet setWithCapacity: [self count]];
@ -1017,6 +1021,7 @@ static SEL rlSel;
- removeObserver:forKeyPath:
- removeObserver:forKeyPath:context:
*/
- (NSUInteger)_countForObject: (id)object // required override...
{
return 1;
@ -1025,28 +1030,18 @@ static SEL rlSel;
// Comparing Sets
- (BOOL) isEqualToOrderedSet: (NSOrderedSet *)aSet
{
if ([self count] == 0 &&
[aSet count] == 0)
return YES;
if (self == aSet)
return YES;
if ([self count] != [aSet count])
return NO;
else
{
id o, e = [self objectEnumerator];
while ((o = [e nextObject]))
{
if (![aSet containsObject: o])
{
return NO;
}
else
{
if ([self _countForObject: o] != [aSet _countForObject: o])
{
return NO;
}
}
}
}
return YES;
// if they are equal, then this set will be a subset of aSet.
return [self isSubsetOfOrderedSet: aSet];
}
- (BOOL) isEqual: (id)other
@ -1149,7 +1144,7 @@ static SEL rlSel;
// Creating a Sorted Array
- (NSArray *) sortedArrayUsingDescriptors:(NSArray *)sortDescriptors
{
NSMutableArray *sortedArray = [GSMutableArray arrayWithArray: [self array]];
NSMutableArray *sortedArray = [NSMutableArray arrayWithArray: [self array]];
[sortedArray sortUsingDescriptors: sortDescriptors];
@ -1196,13 +1191,13 @@ static SEL rlSel;
- (NSString *) descriptionWithLocale: (NSLocale *)locale
{
NSArray *allObjects = [self sortedArrayUsingDescriptors: nil];
return [allObjects descriptionWithLocale: locale];
return [self descriptionWithLocale: locale indent: NO];
}
- (NSString*) descriptionWithLocale: (NSLocale *)locale indent: (BOOL)flag
{
return [self descriptionWithLocale: locale];
NSArray *allObjects = [self array];
return [NSString stringWithFormat: @"%@", allObjects];
}
- (NSArray *) array

View file

@ -6,7 +6,7 @@ int main()
{
START_SET("NSOrderedSet base")
NSOrderedSet *testObj, *testObj2;
NSOrderedSet *testObj, *testObj2;
NSMutableOrderedSet *mutableTest1, *mutableTest2;
NSMutableArray *testObjs = [NSMutableArray new];
@ -148,6 +148,19 @@ int main()
isSubset = [mutableTest2 isSubsetOfOrderedSet:mutableTest1];
PASS(isSubset == NO,
"mutableTest2 is NOT subset of mutableTest1");
o9 = @"Hello";
o10 = @"World";
o11 = @"Ready";
o12 = @"ToGo";
mutableTest1 = [NSMutableOrderedSet orderedSet];
[mutableTest1 addObject:o9];
[mutableTest2 addObject:o10];
[mutableTest2 addObject:o12];
[mutableTest2 addObject:o11];
[testObjs addObject: mutableTest1];
PASS([mutableTest1 isEqual:mutableTest1],
"mutableTest1 is equal to itself");
test_NSObject(@"NSOrderedSet", testObjs);
test_NSCoding(testObjs);