From c263f8daf7a89055f4d01ea0f5d120a159bbd93b Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 6 Feb 2010 17:56:58 +0000 Subject: [PATCH] volatile cache improvement --- src/disk_io_thread.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 8dd56df60..39af9989d 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -1229,11 +1229,19 @@ namespace libtorrent buffer_offset += to_copy; if (m_settings.volatile_read_cache) { - free_buffer(p.blocks[block].buf); - p.blocks[block].buf = 0; - --p.num_blocks; - --m_cache_stats.cache_size; - --m_cache_stats.read_cache_size; + // if volatile read cache is set, the assumption is + // that no other peer is likely to request the same + // piece. Therefore, for each request out of the cache + // we clear the block that was requested and any blocks + // the peer skipped + for (int i = block; i >= 0 && p.blocks[i].buf; --i) + { + free_buffer(p.blocks[i].buf); + p.blocks[i].buf = 0; + --p.num_blocks; + --m_cache_stats.cache_size; + --m_cache_stats.read_cache_size; + } } ++block; }