Don't use any instance variables to control parsing, use the parser's context info. Refs #13362.
authorZachary West <zacw@adium.im>
Wed Nov 25 22:41:51 2009 -0500 (2009-11-25)
changeset 28222a385da3eace
parent 2821 fa988de96a94
child 2823 24c471ce6c9e
Don't use any instance variables to control parsing, use the parser's context info. Refs #13362.
Source/DCMessageContextDisplayPlugin.h
Source/DCMessageContextDisplayPlugin.m
     1.1 --- a/Source/DCMessageContextDisplayPlugin.h	Wed Nov 25 22:34:07 2009 -0500
     1.2 +++ b/Source/DCMessageContextDisplayPlugin.h	Wed Nov 25 22:41:51 2009 -0500
     1.3 @@ -31,13 +31,9 @@
     1.4  	BOOL							isObserving;
     1.5  	BOOL							shouldDisplay;
     1.6  	BOOL							dimRecentContext;
     1.7 -	NSInteger								linesToDisplay;
     1.8 +	NSInteger						linesToDisplay;
     1.9  	
    1.10  	DCMessageContextDisplayPreferences  *preferences;
    1.11 -	
    1.12 -	NSMutableArray	  *foundMessages;
    1.13 -	NSMutableArray	  *elementStack;
    1.14 -	NSAutoreleasePool *parsingAutoreleasePool;
    1.15  }
    1.16  
    1.17  @end
     2.1 --- a/Source/DCMessageContextDisplayPlugin.m	Wed Nov 25 22:34:07 2009 -0500
     2.2 +++ b/Source/DCMessageContextDisplayPlugin.m	Wed Nov 25 22:41:51 2009 -0500
     2.3 @@ -164,6 +164,9 @@
     2.4  	//Initialize a place to store found messages
     2.5  	NSMutableArray *outerFoundContentContexts = [NSMutableArray arrayWithCapacity:linesLeftToFind]; 
     2.6  
     2.7 +	// These set of file's autorelease pool.
     2.8 +	NSAutoreleasePool *parsingAutoreleasePool = [[NSAutoreleasePool alloc] init];
     2.9 +	
    2.10  	//Iterate over the elements of the log path array.
    2.11  	NSEnumerator *pathsEnumerator = [logPaths objectEnumerator];
    2.12  	NSString *logPath = nil;
    2.13 @@ -193,8 +196,8 @@
    2.14  		}
    2.15  
    2.16  		//Initialize the found messages array and element stack for us-as-delegate
    2.17 -		foundMessages = [NSMutableArray arrayWithCapacity:linesLeftToFind];
    2.18 -		elementStack = [NSMutableArray array];
    2.19 +		NSMutableArray *foundMessages = [NSMutableArray arrayWithCapacity:linesLeftToFind];
    2.20 +		NSMutableArray *elementStack = [NSMutableArray array];
    2.21  
    2.22  		//Create the parser and set ourselves as the delegate
    2.23  		LMXParser *parser = [LMXParser parser];
    2.24 @@ -216,6 +219,8 @@
    2.25  						   chat, @"Chat",
    2.26  						   decoder, @"AIHTMLDecoder",
    2.27  						   [NSValue valueWithPointer:&linesLeftToFind], @"LinesLeftToFindValue",
    2.28 +						   foundMessages, @"FoundMessages",
    2.29 +						   elementStack, @"ElementStack",
    2.30  						   nil];
    2.31  			[parser setContextInfo:(void *)contextInfo];
    2.32  		}
    2.33 @@ -232,8 +237,6 @@
    2.34  		off_t offset = [file offsetInFile];
    2.35  		enum LMXParseResult result = LMXParsedIncomplete;
    2.36  
    2.37 -		parsingAutoreleasePool = [[NSAutoreleasePool alloc] init];
    2.38 -
    2.39  		do {
    2.40  			//Calculate the new offset
    2.41  			offset = (offset <= readSize) ? 0 : offset - readSize;
    2.42 @@ -252,8 +255,8 @@
    2.43  		//Continue to parse as long as we need more elements, we have data to read, and LMX doesn't think we're done.
    2.44  		} while ([foundMessages count] < linesLeftToFind && offset > 0 && result != LMXParsedCompletely);
    2.45  
    2.46 -		//Pop our autorelease pool.
    2.47 -		[parsingAutoreleasePool release]; parsingAutoreleasePool = nil;
    2.48 +		//Drain our autorelease pool.
    2.49 +		[parsingAutoreleasePool drain];
    2.50  
    2.51  		//Be a good citizen and close the file
    2.52  		[file closeFile];
    2.53 @@ -263,6 +266,8 @@
    2.54  		linesLeftToFind -= [outerFoundContentContexts count];
    2.55  	}
    2.56  	
    2.57 +	[parsingAutoreleasePool release];
    2.58 +	
    2.59  	if (linesLeftToFind > 0) {
    2.60  		AILogWithSignature(@"Unable to find %d logs for %@", linesLeftToFind, chat);
    2.61  	}
    2.62 @@ -274,6 +279,9 @@
    2.63  
    2.64  - (void)parser:(LMXParser *)parser elementEnded:(NSString *)elementName
    2.65  {
    2.66 +	NSMutableDictionary *contextInfo = [parser contextInfo];
    2.67 +	NSMutableArray *elementStack = [contextInfo objectForKey:@"ElementStack"];
    2.68 +	
    2.69  	if ([elementName isEqualToString:@"message"]) {
    2.70  		[elementStack insertObject:[AIXMLElement elementWithName:elementName] atIndex:0U];
    2.71  	}
    2.72 @@ -286,20 +294,27 @@
    2.73  
    2.74  - (void)parser:(LMXParser *)parser foundCharacters:(NSString *)string
    2.75  {
    2.76 +	NSMutableDictionary *contextInfo = [parser contextInfo];
    2.77 +	NSMutableArray *elementStack = [contextInfo objectForKey:@"ElementStack"];
    2.78 +	
    2.79  	if ([elementStack count])
    2.80  		[(AIXMLElement *)[elementStack objectAtIndex:0U] insertObject:string atIndex:0U];
    2.81  }
    2.82  
    2.83  - (void)parser:(LMXParser *)parser elementStarted:(NSString *)elementName attributes:(NSDictionary *)attributes
    2.84  {
    2.85 +	NSMutableDictionary *contextInfo = [parser contextInfo];
    2.86 +	NSMutableArray *elementStack = [contextInfo objectForKey:@"ElementStack"];
    2.87 +	
    2.88  	if ([elementStack count]) {
    2.89  		AIXMLElement *element = [elementStack objectAtIndex:0U];
    2.90  		if (attributes) {
    2.91  			[element setAttributeNames:[attributes allKeys] values:[attributes allValues]];
    2.92  		}
    2.93  		
    2.94 -		NSMutableDictionary *contextInfo = [parser contextInfo];
    2.95 -
    2.96 +		NSMutableArray	*foundMessages = [contextInfo objectForKey:@"FoundMessagesValue"];
    2.97 +		NSInteger	 *linesLeftToFind = [[contextInfo objectForKey:@"LinesLeftToFindValue"] pointerValue];
    2.98 +		
    2.99  		if ([elementName isEqualToString:@"message"]) {
   2.100  			//A message element has started!
   2.101  			//This means that we have all of this message now, and therefore can create a single content object from the AIXMLElement tree and then throw away that tree.
   2.102 @@ -353,8 +368,6 @@
   2.103  			}
   2.104  		}
   2.105  		
   2.106 -		NSInteger	 *linesLeftToFind = [[contextInfo objectForKey:@"LinesLeftToFindValue"] pointerValue];
   2.107 -
   2.108  		[elementStack removeObjectAtIndex:0U];
   2.109  		if ([foundMessages count] == *linesLeftToFind) {
   2.110  			if ([elementStack count]) [elementStack removeAllObjects];