Skip to content

Commit 12b0ebf

Browse files
committed
cleanup
1 parent b6235b9 commit 12b0ebf

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/metadata/cache.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,31 +88,30 @@ impl SequentialCache {
8888
/// A MetadataFetch implementation that caches fetched data in exponentially growing chunks,
8989
/// sequentially from the beginning of the file.
9090
pub struct ExponentialMetadataCache<F: MetadataFetch> {
91-
fetch: Arc<F>,
91+
inner: F,
9292
cache: Arc<Mutex<SequentialCache>>,
9393
}
9494

9595
impl<F: MetadataFetch> ExponentialMetadataCache<F> {
9696
/// Create a new ExponentialMetadataCache wrapping the given MetadataFetch
97-
pub fn new(fetch: F) -> AsyncTiffResult<Self> {
97+
pub fn new(inner: F) -> AsyncTiffResult<Self> {
9898
Ok(Self {
99-
fetch: Arc::new(fetch),
99+
inner,
100100
cache: Arc::new(Mutex::new(SequentialCache::new())),
101101
})
102102
}
103103
}
104104

105105
fn next_fetch_size(existing_len: u64) -> u64 {
106-
let min = 64 * 1024;
107106
if existing_len == 0 {
108-
return min;
107+
64 * 1024
108+
} else {
109+
existing_len * 2
109110
}
110-
existing_len * 2
111111
}
112112

113113
impl<F: MetadataFetch + Send + Sync> MetadataFetch for ExponentialMetadataCache<F> {
114114
fn fetch(&self, range: Range<u64>) -> BoxFuture<'_, AsyncTiffResult<Bytes>> {
115-
let inner = self.fetch.clone();
116115
let cache = self.cache.clone();
117116

118117
Box::pin(async move {
@@ -131,7 +130,7 @@ impl<F: MetadataFetch + Send + Sync> MetadataFetch for ExponentialMetadataCache<
131130

132131
// Perform the fetch while holding mutex
133132
// (this is OK because the mutex is async)
134-
let bytes = inner.fetch(fetch_range).await?;
133+
let bytes = self.inner.fetch(fetch_range).await?;
135134

136135
// Now append safely
137136
g.append_buffer(bytes);

0 commit comments

Comments
 (0)