diff --git a/benches/benchmarks.rs b/benches/benchmarks.rs index f7b0284..6d2345c 100644 --- a/benches/benchmarks.rs +++ b/benches/benchmarks.rs @@ -1,51 +1,47 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this file, -// You can obtain one at http://mozilla.org/MPL/2.0/. - use async_std::task; use cacache; use criterion::{black_box, criterion_group, criterion_main, Criterion}; use tempfile; -fn read_hash(c: &mut Criterion) { +fn get_hash(c: &mut Criterion) { let tmp = tempfile::tempdir().unwrap(); let cache = tmp.path().to_owned(); let data = b"hello world".to_vec(); let sri = cacache::put::data(&cache, "hello", data).unwrap(); - c.bench_function("read_hash", move |b| { - b.iter(|| cacache::get::read_hash(black_box(&cache), black_box(&sri)).unwrap()) + c.bench_function("get_hash", move |b| { + b.iter(|| cacache::get::data_hash(black_box(&cache), black_box(&sri)).unwrap()) }); } -fn read(c: &mut Criterion) { +fn get(c: &mut Criterion) { let tmp = tempfile::tempdir().unwrap(); let cache = tmp.path().to_owned(); let data = b"hello world".to_vec(); cacache::put::data(&cache, "hello", data).unwrap(); - cacache::get::read(&cache, "hello").unwrap(); - c.bench_function("read", move |b| { - b.iter(|| cacache::get::read(black_box(&cache), black_box(String::from("hello"))).unwrap()) + cacache::get::data(&cache, "hello").unwrap(); + c.bench_function("get", move |b| { + b.iter(|| cacache::get::data(black_box(&cache), black_box(String::from("hello"))).unwrap()) }); } -fn read_hash_big_data(c: &mut Criterion) { +fn get_hash_big_data(c: &mut Criterion) { let tmp = tempfile::tempdir().unwrap(); let cache = tmp.path().to_owned(); let data = vec![1; 1024 * 1024 * 5]; let sri = cacache::put::data(&cache, "hello", data).unwrap(); - c.bench_function("read_hash_big_data", move |b| { - b.iter(|| cacache::get::read_hash(black_box(&cache), black_box(&sri)).unwrap()) + c.bench_function("get_hash_big_data", move |b| { + b.iter(|| cacache::get::data_hash(black_box(&cache), black_box(&sri)).unwrap()) }); } -fn async_read_hash(c: &mut Criterion) { +fn async_get_hash(c: &mut Criterion) { let tmp = tempfile::tempdir().unwrap(); let cache = tmp.path().to_owned(); let data = b"hello world".to_vec(); let sri = cacache::put::data(&cache, "hello", data).unwrap(); - c.bench_function("async_read_hash", move |b| { + c.bench_function("async_get_hash", move |b| { b.iter(|| { - task::block_on(cacache::async_get::read_hash( + task::block_on(cacache::async_get::data_hash( black_box(&cache), black_box(&sri), )) @@ -54,14 +50,14 @@ fn async_read_hash(c: &mut Criterion) { }); } -fn async_read(c: &mut Criterion) { +fn async_get(c: &mut Criterion) { let tmp = tempfile::tempdir().unwrap(); let cache = tmp.path().to_owned(); let data = b"hello world".to_vec(); cacache::put::data(&cache, "hello", data).unwrap(); - c.bench_function("async_read", move |b| { + c.bench_function("async_get", move |b| { b.iter(|| { - task::block_on(cacache::async_get::read( + task::block_on(cacache::async_get::data( black_box(&cache), black_box("hello"), )) @@ -70,14 +66,14 @@ fn async_read(c: &mut Criterion) { }); } -fn async_read_hash_big_data(c: &mut Criterion) { +fn async_get_hash_big_data(c: &mut Criterion) { let tmp = tempfile::tempdir().unwrap(); let cache = tmp.path().to_owned(); let data = vec![1; 1024 * 1024 * 5]; let sri = cacache::put::data(&cache, "hello", data).unwrap(); - c.bench_function("async_read_hash_big_data", move |b| { + c.bench_function("async_get_hash_big_data", move |b| { b.iter(|| { - task::block_on(cacache::async_get::read_hash( + task::block_on(cacache::async_get::data_hash( black_box(&cache), black_box(&sri), )) @@ -88,11 +84,11 @@ fn async_read_hash_big_data(c: &mut Criterion) { criterion_group!( benches, - read_hash, - read, - async_read_hash, - async_read, - read_hash_big_data, - async_read_hash_big_data, + get_hash, + get, + async_get_hash, + async_get, + get_hash_big_data, + async_get_hash_big_data, ); criterion_main!(benches); diff --git a/src/async_get.rs b/src/async_get.rs index 54c20e4..4bfe0c1 100644 --- a/src/async_get.rs +++ b/src/async_get.rs @@ -67,13 +67,13 @@ where /// Reads the entire contents of a cache file into a bytes vector, looking the /// data up by key. -pub async fn read(cache: P, key: K) -> Result, Error> +pub async fn data(cache: P, key: K) -> Result, Error> where P: AsRef, K: AsRef, { if let Some(entry) = index::find_async(cache.as_ref(), key.as_ref()).await? { - read_hash(cache, &entry.integrity).await + data_hash(cache, &entry.integrity).await } else { Err(Error::NotFound) } @@ -81,8 +81,7 @@ where /// Reads the entire contents of a cache file into a bytes vector, looking the /// data up by its content address. -#[allow(clippy::needless_lifetimes)] -pub async fn read_hash

(cache: P, sri: &Integrity) -> Result, Error> +pub async fn data_hash

(cache: P, sri: &Integrity) -> Result, Error> where P: AsRef, { @@ -104,7 +103,6 @@ where } /// Copies a cache entry by integrity address to a specified location. -#[allow(clippy::needless_lifetimes)] pub async fn copy_hash(cache: P, sri: &Integrity, to: Q) -> Result where P: AsRef, diff --git a/src/async_put.rs b/src/async_put.rs index 330ecd8..1ef42f1 100644 --- a/src/async_put.rs +++ b/src/async_put.rs @@ -121,7 +121,7 @@ mod tests { task::block_on(async { data(&dir, "hello", b"hello").await.unwrap(); }); - let data = task::block_on(async { async_get::read(&dir, "hello").await.unwrap() }); + let data = task::block_on(async { async_get::data(&dir, "hello").await.unwrap() }); assert_eq!(data, b"hello"); } } diff --git a/src/get.rs b/src/get.rs index 473aaf1..2ff6348 100644 --- a/src/get.rs +++ b/src/get.rs @@ -57,13 +57,13 @@ where /// Reads the entire contents of a cache file into a bytes vector, looking the /// data up by key. -pub fn read(cache: P, key: K) -> Result, Error> +pub fn data(cache: P, key: K) -> Result, Error> where P: AsRef, K: AsRef, { if let Some(entry) = index::find(cache.as_ref(), key.as_ref())? { - read_hash(cache, &entry.integrity) + data_hash(cache, &entry.integrity) } else { Err(Error::NotFound) } @@ -71,7 +71,7 @@ where /// Reads the entire contents of a cache file into a bytes vector, looking the /// data up by its content address. -pub fn read_hash

(cache: P, sri: &Integrity) -> Result, Error> +pub fn data_hash

(cache: P, sri: &Integrity) -> Result, Error> where P: AsRef, { diff --git a/src/put.rs b/src/put.rs index b194b1b..c613f8f 100644 --- a/src/put.rs +++ b/src/put.rs @@ -160,14 +160,13 @@ impl Put { #[cfg(test)] mod tests { use super::*; - use crate::get; #[test] fn round_trip() { let tmp = tempfile::tempdir().unwrap(); let dir = tmp.path().to_owned(); data(&dir, "hello", b"hello").unwrap(); - let data = get::read(&dir, "hello").unwrap(); + let data = crate::get::data(&dir, "hello").unwrap(); assert_eq!(data, b"hello"); } }