-
Notifications
You must be signed in to change notification settings - Fork 10
Improve binary search performance time for diff creation #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,10 +276,20 @@ static int64_t search(int64_t *I, u_char *old, int64_t oldsize, | |
} | ||
|
||
x = st + (en - st) / 2; | ||
if (memcmp(old + I[x], new, MIN(oldsize - I[x], newsize)) < 0) { | ||
|
||
int64_t length = MIN(oldsize - I[x], newsize); | ||
int result = memcmp(old + I[x], new, length); | ||
|
||
if (result < 0) { | ||
return search(I, old, oldsize, new, newsize, x, en, pos); | ||
} else { | ||
} else if (result > 0) { | ||
return search(I, old, oldsize, new, newsize, st, x, pos); | ||
} else { | ||
/* As a special case, short circuit for the first exact match | ||
* between old_data and new_data, since future exact matches | ||
* will have shorter length. */ | ||
*pos = I[en]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before assign a value to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function that populates the |
||
return length; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this else is not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, yes, but this is a style preference. I think having the
else
block keeps the code in a more maintainable state, since it is linked (conceptually) to thememcmp
result.