From b9c7ce03b7c2c121c599e36000b68996dd762f1c Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Tue, 16 Nov 2010 01:29:48 +0000 Subject: - Attempt to improve QuickLook crashes by using a pool around the area causing crashes on certain files (lines 420,422) - Improve SQL wrapping --- Source/GeneratePreviewForURL.m | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'Source') diff --git a/Source/GeneratePreviewForURL.m b/Source/GeneratePreviewForURL.m index cef1e4ad..ba123c89 100644 --- a/Source/GeneratePreviewForURL.m +++ b/Source/GeneratePreviewForURL.m @@ -383,6 +383,8 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, BOOL skipFontTag; // now loop through all the tokens + NSUInteger poolCount = 0; + NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init]; while (token=yylex()){ skipFontTag = NO; switch (token) { @@ -424,20 +426,36 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, if(truncatedString) [truncatedString release], sqlHTML = nil; if(sqlText) [sqlText release], sqlHTML = nil; if(pool) [pool release], pool = nil; + [loopPool release]; return noErr; } - + poolCount++; + if (poolCount > 1000) { + poolCount = 0; + [loopPool release]; + loopPool = [[NSAutoreleasePool alloc] init]; + } } + [loopPool release]; + [sqlHTML appendString:sqlText]; [sqlHTML appendString:truncatedString]; [sqlText release]; [truncatedString release]; } + // Wrap lines, and replace tabs with spaces + [sqlHTML replaceOccurrencesOfString:@"\n" withString:@"
" options:NSLiteralSearch range:NSMakeRange(0, [sqlHTML length])]; + [sqlHTML replaceOccurrencesOfString:@"\t" withString:@"    " options:NSLiteralSearch range:NSMakeRange(0, [sqlHTML length])]; + + // Improve soft wrapping my making more characters wrap points + [sqlHTML replaceOccurrencesOfString:@"," withString:@",​" options:NSLiteralSearch range:NSMakeRange(0, [sqlHTML length])]; + [sqlHTML replaceOccurrencesOfString:@"/" withString:@"/​" options:NSLiteralSearch range:NSMakeRange(0, [sqlHTML length])]; + html = [NSString stringWithFormat:template, [NSString stringForByteSize:[[fileAttributes objectForKey:NSFileSize] longLongValue]], - [[sqlHTML stringByReplacingOccurrencesOfString:@"\t" withString:@"    "] stringByReplacingOccurrencesOfString:@"\n" withString:@"
"] + sqlHTML ]; previewHeight = 495; [sqlHTML release]; -- cgit v1.2.3