Skip to content

Commit

Permalink
Check for deadline only if there is a valid value for it.
Browse files Browse the repository at this point in the history
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
JanX2 committed Jun 22, 2012
1 parent a4b4488 commit d8c2f07
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions DiffMatchPatch.m
Expand Up @@ -730,7 +730,9 @@ - (NSMutableArray *)diff_bisectOfOldString:(NSString *)_text1
if (text2_buffer != NULL) free(text2_buffer);\ if (text2_buffer != NULL) free(text2_buffer);\
free(v1);\ free(v1);\
free(v2); free(v2);


BOOL validDeadline = (deadline != [[NSDate distantFuture] timeIntervalSinceReferenceDate]);

CFStringRef text1 = (CFStringRef)_text1; CFStringRef text1 = (CFStringRef)_text1;
CFStringRef text2 = (CFStringRef)_text2; CFStringRef text2 = (CFStringRef)_text2;


Expand Down Expand Up @@ -772,7 +774,7 @@ - (NSMutableArray *)diff_bisectOfOldString:(NSString *)_text1
NSMutableArray *diffs; NSMutableArray *diffs;
for (CFIndex d = 0; d < max_d; d++) { for (CFIndex d = 0; d < max_d; d++) {
// Bail out if deadline is reached. // Bail out if deadline is reached.
if ([NSDate timeIntervalSinceReferenceDate] > deadline) { if (validDeadline && ([NSDate timeIntervalSinceReferenceDate] > deadline)) {
break; break;
} }


Expand Down

0 comments on commit d8c2f07

Please sign in to comment.