Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…oping or dereferencing in all languages.
  • Loading branch information...
commit e9e90770d665f44fe0e567344aa60f8f329ce90b 1 parent 77498ff
Jan authored January 15, 2012

Showing 1 changed file with 19 additions and 21 deletions. Show diff stats Hide diff stats

  1. 40  DiffMatchPatch.m
40  DiffMatchPatch.m
@@ -494,27 +494,25 @@ - (NSMutableArray *)diff_computeFromOldString:(NSString *)text1
494 494
     return diffs;
495 495
   }
496 496
 
497  
-  {
498  
-    // New scope so as to garbage collect longtext and shorttext.
499  
-    NSString *longtext = text1.length > text2.length ? text1 : text2;
500  
-    NSString *shorttext = text1.length > text2.length ? text2 : text1;
501  
-    NSUInteger i = [longtext rangeOfString:shorttext].location;
502  
-    if (i != NSNotFound) {
503  
-      // Shorter text is inside the longer text (speedup).
504  
-      Operation op = (text1.length > text2.length) ? DIFF_DELETE : DIFF_INSERT;
505  
-      [diffs addObject:[Diff diffWithOperation:op andText:[longtext substringToIndex:i]]];
506  
-      [diffs addObject:[Diff diffWithOperation:DIFF_EQUAL andText:shorttext]];
507  
-      [diffs addObject:[Diff diffWithOperation:op andText:[longtext substringFromIndex:(i + shorttext.length)]]];
508  
-      return diffs;
509  
-    }
510  
-    
511  
-    if (shorttext.length == 1) {
512  
-      // Single character string.
513  
-      // After the previous speedup, the character can't be an equality.
514  
-      [diffs addObject:[Diff diffWithOperation:DIFF_DELETE andText:text1]];
515  
-      [diffs addObject:[Diff diffWithOperation:DIFF_INSERT andText:text2]];
516  
-      return diffs;
517  
-    }
  497
+  // New scope so as to garbage collect longtext and shorttext.
  498
+  NSString *longtext = text1.length > text2.length ? text1 : text2;
  499
+  NSString *shorttext = text1.length > text2.length ? text2 : text1;
  500
+  NSUInteger i = [longtext rangeOfString:shorttext].location;
  501
+  if (i != NSNotFound) {
  502
+    // Shorter text is inside the longer text (speedup).
  503
+    Operation op = (text1.length > text2.length) ? DIFF_DELETE : DIFF_INSERT;
  504
+    [diffs addObject:[Diff diffWithOperation:op andText:[longtext substringToIndex:i]]];
  505
+    [diffs addObject:[Diff diffWithOperation:DIFF_EQUAL andText:shorttext]];
  506
+    [diffs addObject:[Diff diffWithOperation:op andText:[longtext substringFromIndex:(i + shorttext.length)]]];
  507
+    return diffs;
  508
+  }
  509
+  
  510
+  if (shorttext.length == 1) {
  511
+    // Single character string.
  512
+    // After the previous speedup, the character can't be an equality.
  513
+    [diffs addObject:[Diff diffWithOperation:DIFF_DELETE andText:text1]];
  514
+    [diffs addObject:[Diff diffWithOperation:DIFF_INSERT andText:text2]];
  515
+    return diffs;
518 516
   }
519 517
 
520 518
   // Check to see if the problem can be split in two.

0 notes on commit e9e9077

Please sign in to comment.
Something went wrong with that request. Please try again.