From 695d8051d255f89abf3ec73f806049ca77f4008a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 21 Nov 2008 17:10:20 +0100 Subject: input_curl: try to seek by fast-forwarding the buffer If the caller attempts to seek only a few bytes forward, chances are good that the offset is already in the buffer. In this case, simply fast-forward the buffer. --- src/input_curl.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src') diff --git a/src/input_curl.c b/src/input_curl.c index ad575118d..551a44f4a 100644 --- a/src/input_curl.c +++ b/src/input_curl.c @@ -604,6 +604,32 @@ input_curl_seek(struct input_stream *is, off_t offset, int whence) if (offset < 0) return false; + /* check if we can fast-forward the buffer */ + + while (offset > is->offset && !list_empty(&c->buffers)) { + struct list_head *rewind_head; + struct buffer *buffer = (struct buffer *)c->buffers.next; + size_t length; + + if (!list_empty(&c->rewind) || is->offset == 0) + /* at the beginning or already writing the rewind + buffer list */ + rewind_head = &c->rewind; + else + /* we don't need the rewind buffers anymore */ + rewind_head = NULL; + + length = buffer->size - buffer->consumed; + if (offset - is->offset < (off_t)length) + length = offset - is->offset; + + consume_buffer(buffer, length, rewind_head); + is->offset += length; + } + + if (offset == is->offset) + return true; + /* close the old connection and open a new one */ input_curl_easy_free(c); -- cgit v1.2.3