From b4fc185dc550cda3ef9495eff75bfe50bc7a59d2 Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Wed, 25 Nov 2020 13:51:56 +0900 Subject: [PATCH] Applied CR comments --- src/directory/file_slice.rs | 4 ++-- src/directory/mmap_directory.rs | 8 ++++---- src/directory/mod.rs | 2 +- src/directory/owned_bytes.rs | 2 +- src/indexer/delete_queue.rs | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/directory/file_slice.rs b/src/directory/file_slice.rs index d11625662..cc2b97aa6 100644 --- a/src/directory/file_slice.rs +++ b/src/directory/file_slice.rs @@ -5,8 +5,8 @@ use crate::directory::OwnedBytes; use std::sync::{Arc, Weak}; use std::{io, ops::Deref}; -pub type BoxedData = Arc + Send + Sync + 'static>; -pub type WeakBoxedData = Weak + Send + Sync + 'static>; +pub type ArcBytes = Arc + Send + Sync + 'static>; +pub type WeakArcBytes = Weak + Send + Sync + 'static>; /// Objects that represents files sections in tantivy. /// diff --git a/src/directory/mmap_directory.rs b/src/directory/mmap_directory.rs index 050031ab2..122a366d8 100644 --- a/src/directory/mmap_directory.rs +++ b/src/directory/mmap_directory.rs @@ -8,7 +8,7 @@ use crate::directory::Lock; use crate::directory::WatchCallback; use crate::directory::WatchHandle; use crate::directory::{AntiCallToken, FileHandle, OwnedBytes}; -use crate::directory::{BoxedData, WeakBoxedData}; +use crate::directory::{ArcBytes, WeakArcBytes}; use crate::directory::{TerminatingWrite, WritePtr}; use fs2::FileExt; use memmap::Mmap; @@ -76,7 +76,7 @@ pub struct CacheInfo { struct MmapCache { counters: CacheCounters, - cache: HashMap, + cache: HashMap, } impl Default for MmapCache { @@ -110,7 +110,7 @@ impl MmapCache { } // Returns None if the file exists but as a len of 0 (and hence is not mmappable). - fn get_mmap(&mut self, full_path: &Path) -> Result, OpenReadError> { + fn get_mmap(&mut self, full_path: &Path) -> Result, OpenReadError> { if let Some(mmap_weak) = self.cache.get(full_path) { if let Some(mmap_arc) = mmap_weak.upgrade() { self.counters.hit += 1; @@ -121,7 +121,7 @@ impl MmapCache { self.counters.miss += 1; let mmap_opt = open_mmap(full_path)?; Ok(mmap_opt.map(|mmap| { - let mmap_arc: BoxedData = Arc::new(mmap); + let mmap_arc: ArcBytes = Arc::new(mmap); let mmap_weak = Arc::downgrade(&mmap_arc); self.cache.insert(full_path.to_owned(), mmap_weak); mmap_arc diff --git a/src/directory/mod.rs b/src/directory/mod.rs index 9bf01e229..8bd2c3185 100644 --- a/src/directory/mod.rs +++ b/src/directory/mod.rs @@ -23,7 +23,7 @@ pub mod error; pub use self::directory::DirectoryLock; pub use self::directory::{Directory, DirectoryClone}; pub use self::directory_lock::{Lock, INDEX_WRITER_LOCK, META_LOCK}; -pub(crate) use self::file_slice::{BoxedData, WeakBoxedData}; +pub(crate) use self::file_slice::{ArcBytes, WeakArcBytes}; pub use self::file_slice::{FileHandle, FileSlice}; pub use self::owned_bytes::OwnedBytes; pub use self::ram_directory::RAMDirectory; diff --git a/src/directory/owned_bytes.rs b/src/directory/owned_bytes.rs index 8a2f4add4..73303f50c 100644 --- a/src/directory/owned_bytes.rs +++ b/src/directory/owned_bytes.rs @@ -99,7 +99,7 @@ impl OwnedBytes { /// Reads an `u8` from the `OwnedBytes` and advance by one byte. pub fn read_u8(&mut self) -> u8 { - assert!(self.len() > 0); + assert!(!self.is_empty()); let byte = self.as_slice()[0]; self.advance(1); diff --git a/src/indexer/delete_queue.rs b/src/indexer/delete_queue.rs index 3b7b738c8..ba445dd3b 100644 --- a/src/indexer/delete_queue.rs +++ b/src/indexer/delete_queue.rs @@ -53,7 +53,7 @@ impl DeleteQueue { return block; } let block = Arc::new(Block { - operations: Arc::new([DeleteOperation::default(); 0]), + operations: Arc::new([]), next: NextBlock::from(self.clone()), }); wlock.last_block = Arc::downgrade(&block);