Skip to content

Commit

Permalink
fixed leak in CDRRunTimeTitlePair
Browse files Browse the repository at this point in the history
  • Loading branch information
cppforlife committed Oct 6, 2012
1 parent 2878371 commit ca2b2c3
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions Source/ReporterHelpers/CDRSlowTestStatistics.m
Expand Up @@ -23,6 +23,11 @@ + (RunTimeTitlePair *)pairWithRunTime:(NSTimeInterval)runTime title:(NSString *)
return pair;
}

- (void)dealloc {
self.title = nil;
[super dealloc];
}

- (NSString *)formattedDescription {
NSString *timeString = [NSString stringWithFormat:@"%7.3fs | ", self.runTime];
NSString *newLinePrefix = [NSString stringWithFormat:@"\n | "];
Expand All @@ -42,12 +47,10 @@ - (NSString *)formattedDescription {
[currentLine addObject:titleChunk];
currentLineLength += titleChunk.length + 1;
}

[lines addObject:[currentLine componentsJoinedByString:@" "]];

NSString *description = [timeString stringByAppendingString:[lines componentsJoinedByString:newLinePrefix]];

return description;

return [timeString stringByAppendingString:[lines componentsJoinedByString:newLinePrefix]];
}

- (NSComparisonResult)compare:(RunTimeTitlePair *)otherPair {
Expand All @@ -56,10 +59,8 @@ - (NSComparisonResult)compare:(RunTimeTitlePair *)otherPair {
} else if (self.runTime < otherPair.runTime) {
return NSOrderedAscending;
}

return NSOrderedSame;
}

@end

@interface CDRSlowTestStatistics ()
Expand All @@ -82,27 +83,25 @@ - (int)numberOfResultsToShow {
- (void)printStatsForExampleGroups:(NSArray *)groups {
NSMutableArray *rootPairs = [NSMutableArray array];
NSMutableArray *examplePairs = [NSMutableArray array];

for (CDRExampleGroup *group in groups) {
RunTimeTitlePair *pair = [RunTimeTitlePair pairWithRunTime:group.runTime
title:group.text];
[rootPairs addObject:pair];
[rootPairs addObject:[RunTimeTitlePair pairWithRunTime:group.runTime title:group.text]];
[examplePairs addObjectsFromArray:[self runTimeTitlePairsForGroup:group]];
}

int numberOfResultsToShow = self.numberOfResultsToShow;

NSArray *sortedRootPairs = [[[rootPairs sortedArrayUsingSelector:@selector(compare:)] reverseObjectEnumerator] allObjects];
sortedRootPairs = [sortedRootPairs subarrayWithRange:NSMakeRange(0, MIN(numberOfResultsToShow, sortedRootPairs.count))];

NSArray *sortedExamplePairs = [[[examplePairs sortedArrayUsingSelector:@selector(compare:)] reverseObjectEnumerator] allObjects];
sortedExamplePairs = [sortedExamplePairs subarrayWithRange:NSMakeRange(0, MIN(numberOfResultsToShow, sortedExamplePairs.count))];

printf("\n%d Slowest Tests\n\n", (int)sortedExamplePairs.count);
for (RunTimeTitlePair *pair in sortedExamplePairs) {
printf("%s\n\n", pair.formattedDescription.UTF8String);
}

printf("\n%d Slowest Top-Level Groups\n\n", (int)sortedRootPairs.count);
for (RunTimeTitlePair *pair in sortedRootPairs) {
printf("%s\n\n", pair.formattedDescription.UTF8String);
Expand All @@ -111,20 +110,16 @@ - (void)printStatsForExampleGroups:(NSArray *)groups {

- (NSArray *)runTimeTitlePairsForGroup:(CDRExampleGroup *)group {
NSMutableArray *pairs = [NSMutableArray array];

if (group.hasChildren) {
for (CDRExampleBase *example in group.examples) {
if (example.hasChildren) {
[pairs addObjectsFromArray:[self runTimeTitlePairsForGroup:(CDRExampleGroup *) example]];
} else {
RunTimeTitlePair *pair = [RunTimeTitlePair pairWithRunTime:example.runTime
title:example.fullText];
[pairs addObject:pair];
[pairs addObject:[RunTimeTitlePair pairWithRunTime:example.runTime title:example.fullText]];
}
}
}

return pairs;
}

@end

0 comments on commit ca2b2c3

Please sign in to comment.