Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding support for Objective-C Garbage Collection.

  • Loading branch information...
commit 651e85df3c75f3229189d66ab5806dea88cf0353 1 parent 6360e67
@JanX2 authored
View
26 DiffMatchPatch.m
@@ -444,7 +444,7 @@ - (NSUInteger)diff_commonOverlapOfFirstString:(NSString *)text1
- (NSArray *)diff_halfMatchOfFirstString:(NSString *)text1
andSecondString:(NSString *)text2;
{
- return [(NSArray *)diff_halfMatchCreate((CFStringRef)text1, (CFStringRef)text2, Diff_Timeout) autorelease];
+ return [NSMakeCollectable(diff_halfMatchCreate((CFStringRef)text1, (CFStringRef)text2, Diff_Timeout)) autorelease];
}
/**
@@ -461,7 +461,7 @@ - (NSArray *)diff_halfMatchIOfLongString:(NSString *)longtext
andShortString:(NSString *)shorttext
index:(NSInteger)index;
{
- return [((NSArray *)diff_halfMatchICreate((CFStringRef)longtext, (CFStringRef)shorttext, (CFIndex)index)) autorelease];
+ return [NSMakeCollectable(diff_halfMatchICreate((CFStringRef)longtext, (CFStringRef)shorttext, (CFIndex)index)) autorelease];
}
/**
@@ -517,7 +517,7 @@ - (NSMutableArray *)diff_computeFromOldString:(NSString *)text1
longtext = shorttext = nil; // Garbage collect: prevent abandoned memory.
// Check to see if the problem can be split in two.
- NSArray *hm = [(NSArray *)diff_halfMatchCreate((CFStringRef)text1, (CFStringRef)text2, Diff_Timeout) autorelease];
+ NSArray *hm = [NSMakeCollectable(diff_halfMatchCreate((CFStringRef)text1, (CFStringRef)text2, Diff_Timeout)) autorelease];
if (hm != nil) {
NSAutoreleasePool *splitPool = [NSAutoreleasePool new];
// A half-match was found, sort out the return data.
@@ -638,9 +638,9 @@ - (NSString *)diff_linesToCharsMungeOfText:(NSString *)text
lineArray:(NSMutableArray *)lineArray
lineHash:(NSMutableDictionary *)lineHash;
{
- return [((NSString *)diff_linesToCharsMungeCFStringCreate((CFStringRef)text,
- (CFMutableArrayRef)lineArray,
- (CFMutableDictionaryRef)lineHash)) autorelease];
+ return [NSMakeCollectable(diff_linesToCharsMungeCFStringCreate((CFStringRef)text,
+ (CFMutableArrayRef)lineArray,
+ (CFMutableDictionaryRef)lineHash)) autorelease];
}
/**
@@ -862,13 +862,13 @@ - (NSArray *)diff_linesToCharsForFirstString:(NSString *)text1
// So we'll insert a junk entry to avoid generating a nil character.
[lineArray addObject:@""];
- NSString *chars1 = (NSString *)diff_linesToCharsMungeCFStringCreate((CFStringRef)text1,
- (CFMutableArrayRef)lineArray,
- (CFMutableDictionaryRef)lineHash);
- NSString *chars2 = (NSString *)diff_linesToCharsMungeCFStringCreate((CFStringRef)text2,
- (CFMutableArrayRef)lineArray,
- (CFMutableDictionaryRef)lineHash);
-
+ NSString *chars1 = NSMakeCollectable(diff_linesToCharsMungeCFStringCreate((CFStringRef)text1,
+ (CFMutableArrayRef)lineArray,
+ (CFMutableDictionaryRef)lineHash));
+ NSString *chars2 = NSMakeCollectable(diff_linesToCharsMungeCFStringCreate((CFStringRef)text2,
+ (CFMutableArrayRef)lineArray,
+ (CFMutableDictionaryRef)lineHash));
+
NSArray *result = [NSArray arrayWithObjects:chars1, chars2, lineArray, nil];
[chars1 release];
View
4 DiffMatchPatch.xcodeproj/project.pbxproj
@@ -453,6 +453,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 3D510E1012BEBA44008C7CE7 /* Base.xcconfig */;
buildSettings = {
+ GCC_ENABLE_OBJC_GC = supported;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_UNINITIALIZED_AUTOS = NO;
ONLY_ACTIVE_ARCH = YES;
@@ -463,6 +464,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 3D510E1012BEBA44008C7CE7 /* Base.xcconfig */;
buildSettings = {
+ GCC_ENABLE_OBJC_GC = supported;
};
name = Release;
};
@@ -470,6 +472,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 3D105A0912DA5F9D002111E1 /* Base+SnowLeopard.xcconfig */;
buildSettings = {
+ GCC_ENABLE_OBJC_GC = supported;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_UNINITIALIZED_AUTOS = NO;
ONLY_ACTIVE_ARCH = YES;
@@ -551,6 +554,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 3D105A0912DA5F9D002111E1 /* Base+SnowLeopard.xcconfig */;
buildSettings = {
+ GCC_ENABLE_OBJC_GC = supported;
};
name = "Release 10.6";
};
View
6 DiffMatchPatchCFUtilities.c
@@ -44,7 +44,6 @@ CFArrayRef diff_halfMatchICreate(CFStringRef longtext, CFStringRef shorttext, CF
// Utility functions
CFStringRef diff_CFStringCreateFromUnichar(UniChar ch) {
CFStringRef c = CFStringCreateWithCharacters(kCFAllocatorDefault, &ch, 1);
- CFMakeCollectable(c);
return c;
}
@@ -54,7 +53,6 @@ CFStringRef diff_CFStringCreateSubstring(CFStringRef text, CFIndex start_index,
substringRange.location = start_index;
CFStringRef substring = CFStringCreateWithSubstring(kCFAllocatorDefault, text, substringRange);
- CFMakeCollectable(substring);
return substring;
}
@@ -94,7 +92,6 @@ CFStringRef diff_CFStringCreateByCombiningTwoStrings(CFStringRef best_common_par
CFMutableStringRef best_common_mutable;
best_common_length = CFStringGetLength(best_common_part1) + CFStringGetLength(best_common_part2);
best_common_mutable = CFStringCreateMutableCopy(kCFAllocatorDefault, best_common_length, best_common_part1);
- CFMakeCollectable(best_common_mutable);
CFStringAppend(best_common_mutable, best_common_part2);
return best_common_mutable;
}
@@ -343,7 +340,6 @@ CFArrayRef diff_halfMatchCreate(CFStringRef text1, CFStringRef text2, const floa
// => { hm[2], hm[3], hm[0], hm[1], hm[4] }
CFMutableArrayRef hm_mutable = CFArrayCreateMutableCopy(kCFAllocatorDefault, CFArrayGetCount(hm), hm);
- CFMakeCollectable(hm_mutable);
CFRelease(hm);
@@ -431,7 +427,6 @@ CFArrayRef diff_halfMatchICreate(CFStringRef longtext, CFStringRef shorttext, CF
const CFStringRef values[] = { best_longtext_a, best_longtext_b,
best_shorttext_a, best_shorttext_b, best_common };
halfMatchIArray = CFArrayCreate(kCFAllocatorDefault, (const void **)values, (sizeof(values) / sizeof(values[0])), &kCFTypeArrayCallBacks);
- CFMakeCollectable(halfMatchIArray);
} else {
halfMatchIArray = NULL;
}
@@ -492,7 +487,6 @@ CFStringRef diff_linesToCharsMungeCFStringCreate(CFStringRef text, CFMutableArra
CFArrayAppendValue(lineArray, line);
hash = CFArrayGetCount(lineArray) - 1;
hashNumber = CFNumberCreate(kCFAllocatorDefault, kCFNumberCFIndexType, &hash);
- CFMakeCollectable(hashNumber);
CFDictionaryAddValue(lineHash, line, hashNumber);
CFRelease(hashNumber);
const UniChar hashChar = (UniChar)hash;
View
3  NSString+JavaSubstring.m
@@ -29,8 +29,7 @@ @implementation NSString (JavaSubstring)
- (NSString *)diff_javaSubstringFromStart:(NSUInteger)start toEnd:(NSUInteger)end;
{
CFStringRef c = diff_CFStringCreateJavaSubstring((CFStringRef)self, (CFIndex)start, (CFIndex)end);
- CFMakeCollectable(c);
- return [(NSString *)c autorelease];
+ return [NSMakeCollectable(c) autorelease];
}
@end
View
3  NSString+UnicharUtilities.m
@@ -28,8 +28,7 @@ @implementation NSString (UnicharUtilities)
+ (NSString *)diff_stringFromUnichar:(unichar)ch;
{
CFStringRef c = CFStringCreateWithCharacters(kCFAllocatorDefault, &ch, 1);
- CFMakeCollectable(c);
- return [(NSString *)c autorelease];
+ return [NSMakeCollectable(c) autorelease];
}
- (NSString *)diff_substringWithCharacterAtIndex:(NSUInteger)anIndex;
View
6 NSString+UriCompatibility.m
@@ -39,8 +39,7 @@ - (NSString *)diff_stringByAddingPercentEscapesForEncodeUriCompatibility;
CFSTR(" !~*'();/?:@&=+$,#"),
NULL,
kCFStringEncodingUTF8);
- CFMakeCollectable(urlString);
- return [(NSString *)urlString autorelease];
+ return [NSMakeCollectable(urlString) autorelease];
}
/**
@@ -56,8 +55,7 @@ - (NSString *)diff_stringByReplacingPercentEscapesForEncodeUriCompatibility;
(CFStringRef)self,
CFSTR(""),
kCFStringEncodingUTF8);
- CFMakeCollectable(decodedString);
- return [(NSString *)decodedString autorelease];
+ return [NSMakeCollectable(decodedString) autorelease];
}
@end
Please sign in to comment.
Something went wrong with that request. Please try again.