dovecot: i_stream_seek(): If parent stream is set, use skip opti...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Dec 22 05:59:03 EET 2007
details: http://hg.dovecot.org/dovecot/rev/e527ac1a7b4b
changeset: 7034:e527ac1a7b4b
user: Timo Sirainen <tss at iki.fi>
date: Sat Dec 22 05:58:58 2007 +0200
description:
i_stream_seek(): If parent stream is set, use skip optimization only if all
the parent streams are at their expected offsets.
diffstat:
1 file changed, 19 insertions(+), 1 deletion(-)
src/lib/istream.c | 20 +++++++++++++++++++-
diffs (34 lines):
diff -r 5b40343e96c7 -r e527ac1a7b4b src/lib/istream.c
--- a/src/lib/istream.c Sat Dec 22 05:49:26 2007 +0200
+++ b/src/lib/istream.c Sat Dec 22 05:58:58 2007 +0200
@@ -91,11 +91,29 @@ void i_stream_skip(struct istream *strea
_stream->seek(_stream, stream->v_offset + count, FALSE);
}
+static bool i_stream_can_optimize_seek(struct istream *stream)
+{
+ uoff_t expected_offset;
+
+ if (stream->real_stream->parent == NULL)
+ return TRUE;
+
+ /* use the fast route only if the parent stream is at the
+ expected offset */
+ expected_offset = stream->real_stream->parent_start_offset +
+ stream->v_offset - stream->real_stream->skip;
+ if (stream->real_stream->parent->v_offset != expected_offset)
+ return FALSE;
+
+ return i_stream_can_optimize_seek(stream->real_stream->parent);
+}
+
void i_stream_seek(struct istream *stream, uoff_t v_offset)
{
struct istream_private *_stream = stream->real_stream;
- if (v_offset >= stream->v_offset) {
+ if (v_offset >= stream->v_offset &&
+ i_stream_can_optimize_seek(stream)) {
i_stream_skip(stream, v_offset - stream->v_offset);
return;
}
More information about the dovecot-cvs
mailing list