Skip to content
This repository was archived by the owner on Aug 6, 2021. It is now read-only.

Commit 9ef4a83

Browse files
MaddTheSaneC.W. Betts
authored and
C.W. Betts
committed
Convert to ARC.
Use alloc-init instead of convenience class functions: They're not autoreleased, meaning less stress on the autorelease pools.
1 parent a79f2bb commit 9ef4a83

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

GeneratePreviewForURL.m

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
1212
CFURLRef url, CFStringRef contentTypeUTI,
1313
CFDictionaryRef options)
1414
{
15-
CFDataRef data = (CFDataRef) renderMarkdown((NSURL*) url);
15+
@autoreleasepool {
16+
NSData *data = renderMarkdown((__bridge NSURL*) url);
1617

1718
if (data) {
18-
CFDictionaryRef props = (CFDictionaryRef) [NSDictionary dictionary];
19-
QLPreviewRequestSetDataRepresentation(preview, data, kUTTypeHTML, props);
19+
NSDictionary *props = [[NSDictionary alloc] init];
20+
QLPreviewRequestSetDataRepresentation(preview, (__bridge CFDataRef)data, kUTTypeHTML, (__bridge CFDictionaryRef)props);
2021
}
2122

2223
return noErr;
24+
}
2325
}
2426

2527
void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)

GenerateThumbnailForURL.m

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ OSStatus GenerateThumbnailForURL(void *thisInterface,
1919
CFURLRef url, CFStringRef contentTypeUTI,
2020
CFDictionaryRef options, CGSize maxSize)
2121
{
22-
NSData *data = renderMarkdown((NSURL*) url);
22+
@autoreleasepool {
23+
NSData *data = renderMarkdown((__bridge NSURL*) url);
2324

2425
if (data) {
2526
NSRect viewRect = NSMakeRect(0.0, 0.0, 600.0, 800.0);
@@ -29,7 +30,7 @@ OSStatus GenerateThumbnailForURL(void *thisInterface,
2930
NSMakeSize((maxSize.width * (600.0/800.0)),
3031
maxSize.height));
3132

32-
WebView* webView = [[[WebView alloc] initWithFrame: viewRect] autorelease];
33+
WebView* webView = [[WebView alloc] initWithFrame: viewRect];
3334
[webView scaleUnitSquareToSize: scaleSize];
3435
[[[webView mainFrame] frameView] setAllowsScrolling:NO];
3536
[[webView mainFrame] loadData: data
@@ -62,6 +63,7 @@ OSStatus GenerateThumbnailForURL(void *thisInterface,
6263
}
6364

6465
return noErr;
66+
}
6567
}
6668

6769
void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail)

QLMarkdown.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@
334334
2CA3261F0896AD4900168862 /* Debug */ = {
335335
isa = XCBuildConfiguration;
336336
buildSettings = {
337+
CLANG_ENABLE_OBJC_ARC = YES;
337338
COMBINE_HIDPI_IMAGES = YES;
338339
COPY_PHASE_STRIP = NO;
339340
GCC_DYNAMIC_NO_PIC = NO;
@@ -349,6 +350,7 @@
349350
2CA326200896AD4900168862 /* Release */ = {
350351
isa = XCBuildConfiguration;
351352
buildSettings = {
353+
CLANG_ENABLE_OBJC_ARC = YES;
352354
COMBINE_HIDPI_IMAGES = YES;
353355
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
354356
GCC_PRECOMPILE_PREFIX_HEADER = NO;

markdown.m

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33

44
NSData* renderMarkdown(NSURL* url)
55
{
6-
NSString *styles = [NSString stringWithContentsOfFile:[[NSBundle bundleWithIdentifier: @"com.fiatdev.QLMarkdown"]
6+
@autoreleasepool {
7+
NSString *styles = [[NSString alloc] initWithContentsOfFile:[[NSBundle bundleWithIdentifier: @"com.fiatdev.QLMarkdown"]
78
pathForResource:@"styles" ofType:@"css"]
89
encoding:NSUTF8StringEncoding
910
error:nil];
1011

1112
NSStringEncoding usedEncoding = 0;
1213
NSError *e = nil;
1314

14-
NSString *source = [NSString stringWithContentsOfURL:url usedEncoding:&usedEncoding error:&e];
15+
NSString *source = [[NSString alloc] initWithContentsOfURL:url usedEncoding:&usedEncoding error:&e];
1516

1617
if (usedEncoding == 0) {
1718
NSLog(@"Wasn't able to determine encoding for file “%@", [url path]);
@@ -27,4 +28,5 @@
2728

2829
free(output);
2930
return [html dataUsingEncoding:NSUTF8StringEncoding];
31+
}
3032
}

0 commit comments

Comments
 (0)