Permalink
Browse files

Check for deadline only if there is a valid value for it.

This shaves a few percent off of the speedtest, because calling NSDate’s -timeIntervalSinceReferenceDate for every iteration of the loop is expensive and unnecessary if there is no deadline.
  • Loading branch information...
1 parent a4b4488 commit d8c2f07193ece693edaca5f458215d5159ca8b7d @JanX2 committed Jan 31, 2012
Showing with 4 additions and 2 deletions.
  1. +4 −2 DiffMatchPatch.m
View
@@ -730,7 +730,9 @@ - (NSMutableArray *)diff_bisectOfOldString:(NSString *)_text1
if (text2_buffer != NULL) free(text2_buffer);\
free(v1);\
free(v2);
-
+
+ BOOL validDeadline = (deadline != [[NSDate distantFuture] timeIntervalSinceReferenceDate]);
+
CFStringRef text1 = (CFStringRef)_text1;
CFStringRef text2 = (CFStringRef)_text2;
@@ -772,7 +774,7 @@ - (NSMutableArray *)diff_bisectOfOldString:(NSString *)_text1
NSMutableArray *diffs;
for (CFIndex d = 0; d < max_d; d++) {
// Bail out if deadline is reached.
- if ([NSDate timeIntervalSinceReferenceDate] > deadline) {
+ if (validDeadline && ([NSDate timeIntervalSinceReferenceDate] > deadline)) {
break;
}

0 comments on commit d8c2f07

Please sign in to comment.