changeset 13011:66ec075a49d3

zlib: Don't unnecessarily reset istream caches.
author Timo Sirainen <tss@iki.fi>
date Tue, 10 May 2011 18:24:31 +0300
parents 15a0687ec9d0
children 370bf3d2d54f
files src/plugins/zlib/istream-bzlib.c src/plugins/zlib/istream-zlib.c
diffstat 2 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/zlib/istream-bzlib.c	Tue May 10 18:19:35 2011 +0300
+++ b/src/plugins/zlib/istream-bzlib.c	Tue May 10 18:24:31 2011 +0300
@@ -16,6 +16,7 @@
 	bz_stream zs;
 	uoff_t eof_offset;
 	size_t prev_size, high_pos;
+	struct stat last_parent_statbuf;
 
 	unsigned int log_errors:1;
 	unsigned int marked:1;
@@ -300,7 +301,18 @@
 static void i_stream_bzlib_sync(struct istream_private *stream)
 {
 	struct bzlib_istream *zstream = (struct bzlib_istream *) stream;
+	const struct stat *st;
 
+	st = i_stream_stat(stream->parent, FALSE);
+	if (st != NULL) {
+		if (memcmp(&zstream->last_parent_statbuf,
+			   st, sizeof(*st)) == 0) {
+			/* a compressed file doesn't change unexpectedly,
+			   don't clear our caches unnecessarily */
+			return;
+		}
+		zstream->last_parent_statbuf = *st;
+	}
 	i_stream_bzlib_reset(zstream);
 }
 
--- a/src/plugins/zlib/istream-zlib.c	Tue May 10 18:19:35 2011 +0300
+++ b/src/plugins/zlib/istream-zlib.c	Tue May 10 18:24:31 2011 +0300
@@ -28,6 +28,7 @@
 	uoff_t eof_offset;
 	size_t prev_size, high_pos;
 	uint32_t crc32;
+	struct stat last_parent_statbuf;
 
 	unsigned int gz:1;
 	unsigned int log_errors:1;
@@ -446,7 +447,18 @@
 static void i_stream_zlib_sync(struct istream_private *stream)
 {
 	struct zlib_istream *zstream = (struct zlib_istream *) stream;
+	const struct stat *st;
 
+	st = i_stream_stat(stream->parent, FALSE);
+	if (st != NULL) {
+		if (memcmp(&zstream->last_parent_statbuf,
+			   st, sizeof(*st)) == 0) {
+			/* a compressed file doesn't change unexpectedly,
+			   don't clear our caches unnecessarily */
+			return;
+		}
+		zstream->last_parent_statbuf = *st;
+	}
 	i_stream_zlib_reset(zstream);
 }