# [PATCH 2/5] Use new decompress helpers in diff.c

1 messages from 2008-01-10 to 2008-01-10. Participants: Marco Costalba.
Thread: https://gitlist.dev/t/11568

## Marco Costalba, 2008-01-10 21:06

Subject: [PATCH 2/5] Use new decompress helpers in diff.c
Message-ID: <e5bfff550801101306i4e62e339tb9e86414c3e7894e@mail.gmail.com>
URL: https://gitlist.dev/e/e5bfff550801101306i4e62e339tb9e86414c3e7894e%40mail.gmail.com

```
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
---
 diff.c |   22 +++++-----------------
 1 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/diff.c b/diff.c
index b18c140..ecfa721 100644
--- a/diff.c
+++ b/diff.c
@@ -2,6 +2,7 @@
  * Copyright (C) 2005 Junio C Hamano
  */
 #include "cache.h"
+#include "compress.h"
 #include "quote.h"
 #include "diff.h"
 #include "diffcore.h"
@@ -1037,23 +1038,10 @@ static unsigned char *deflate_it(char *data,
 				 unsigned long size,
 				 unsigned long *result_size)
 {
-	int bound;
-	unsigned char *deflated;
-	z_stream stream;
-
-	memset(&stream, 0, sizeof(stream));
-	deflateInit(&stream, zlib_compression_level);
-	bound = deflateBound(&stream, size);
-	deflated = xmalloc(bound);
-	stream.next_out = deflated;
-	stream.avail_out = bound;
-
-	stream.next_in = (unsigned char *)data;
-	stream.avail_in = size;
-	while (deflate(&stream, Z_FINISH) == Z_OK)
-		; /* nothing */
-	deflateEnd(&stream);
-	*result_size = stream.total_out;
+	unsigned char *deflated = NULL;
+
+	*result_size = z_deflate_all(zlib_compression_level,
+                                    (unsigned char *)data, size, &deflated);
 	return deflated;
 }

-- 
1.5.4.rc2.89.g1b3f

```
