Permalink
Browse files

Adding code changes from SVN revision 103: Removing long/shorttext sc…

…oping or dereferencing in all languages.
  • Loading branch information...
JanX2 committed Jan 15, 2012
1 parent 77498ff commit e9e90770d665f44fe0e567344aa60f8f329ce90b
Showing with 19 additions and 21 deletions.
  1. +19 −21 DiffMatchPatch.m
View
@@ -494,27 +494,25 @@ - (NSMutableArray *)diff_computeFromOldString:(NSString *)text1
return diffs;
}
- {
- // New scope so as to garbage collect longtext and shorttext.
- NSString *longtext = text1.length > text2.length ? text1 : text2;
- NSString *shorttext = text1.length > text2.length ? text2 : text1;
- NSUInteger i = [longtext rangeOfString:shorttext].location;
- if (i != NSNotFound) {
- // Shorter text is inside the longer text (speedup).
- Operation op = (text1.length > text2.length) ? DIFF_DELETE : DIFF_INSERT;
- [diffs addObject:[Diff diffWithOperation:op andText:[longtext substringToIndex:i]]];
- [diffs addObject:[Diff diffWithOperation:DIFF_EQUAL andText:shorttext]];
- [diffs addObject:[Diff diffWithOperation:op andText:[longtext substringFromIndex:(i + shorttext.length)]]];
- return diffs;
- }
-
- if (shorttext.length == 1) {
- // Single character string.
- // After the previous speedup, the character can't be an equality.
- [diffs addObject:[Diff diffWithOperation:DIFF_DELETE andText:text1]];
- [diffs addObject:[Diff diffWithOperation:DIFF_INSERT andText:text2]];
- return diffs;
- }
+ // New scope so as to garbage collect longtext and shorttext.
+ NSString *longtext = text1.length > text2.length ? text1 : text2;
+ NSString *shorttext = text1.length > text2.length ? text2 : text1;
+ NSUInteger i = [longtext rangeOfString:shorttext].location;
+ if (i != NSNotFound) {
+ // Shorter text is inside the longer text (speedup).
+ Operation op = (text1.length > text2.length) ? DIFF_DELETE : DIFF_INSERT;
+ [diffs addObject:[Diff diffWithOperation:op andText:[longtext substringToIndex:i]]];
+ [diffs addObject:[Diff diffWithOperation:DIFF_EQUAL andText:shorttext]];
+ [diffs addObject:[Diff diffWithOperation:op andText:[longtext substringFromIndex:(i + shorttext.length)]]];
+ return diffs;
+ }
+
+ if (shorttext.length == 1) {
+ // Single character string.
+ // After the previous speedup, the character can't be an equality.
+ [diffs addObject:[Diff diffWithOperation:DIFF_DELETE andText:text1]];
+ [diffs addObject:[Diff diffWithOperation:DIFF_INSERT andText:text2]];
+ return diffs;
}
// Check to see if the problem can be split in two.

0 comments on commit e9e9077

Please sign in to comment.