From 75c42d8cc3b42e4b82946848b8ba902b4bbcc38d Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 25 Jun 2005 19:30:20 -0700 Subject: Add a "max_size" parameter to diff_delta() Anything that generates a delta to see if two objects are close usually isn't interested in the delta ends up being bigger than some specified size, and this allows us to stop delta generation early when that happens. --- diff-delta.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'diff-delta.c') diff --git a/diff-delta.c b/diff-delta.c index 480f03cd16..fd9b37f491 100644 --- a/diff-delta.c +++ b/diff-delta.c @@ -203,7 +203,8 @@ static void delta_cleanup(bdfile_t *bdf) void *diff_delta(void *from_buf, unsigned long from_size, void *to_buf, unsigned long to_size, - unsigned long *delta_size) + unsigned long *delta_size, + unsigned long max_size) { int i, outpos, outsize, inscnt, csize, msize, moff; unsigned int fp; @@ -312,6 +313,11 @@ void *diff_delta(void *from_buf, unsigned long from_size, } /* next time around the largest possible output is 1 + 4 + 3 */ + if (max_size && outpos > max_size) { + free(out); + delta_cleanup(&bdf); + return NULL; + } if (outpos > outsize - 8) { void *tmp = out; outsize = outsize * 3 / 2; -- cgit v1.2.1