From 0521844e5689ef90a92b229fcd645e83ad1e7c3f Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Wed, 31 May 2017 08:22:53 +0900 Subject: [PATCH] Format, small changes in VInt --- src/common/vint.rs | 13 ++++++------- src/fastfield/reader.rs | 18 +++++++++++------- src/termdict/merger.rs | 2 +- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/common/vint.rs b/src/common/vint.rs index c1a014599..39653e8a7 100644 --- a/src/common/vint.rs +++ b/src/common/vint.rs @@ -19,20 +19,19 @@ impl BinarySerializable for VInt { fn serialize(&self, writer: &mut W) -> io::Result<()> { let mut remaining = self.0; let mut buffer = [0u8; 10]; - let mut written = 0; + let mut i = 0; loop { let next_byte: u8 = (remaining % 128u64) as u8; remaining /= 128u64; if remaining == 0u64 { - buffer[written] = next_byte | 128u8; - written += 1; - break; + buffer[i] = next_byte | 128u8; + return writer.write_all(&buffer[0..i + 1]); } else { - buffer[written] = next_byte; - written += 1; + buffer[i] = next_byte; } + i += 1; } - writer.write_all(&buffer[0..written]) + } fn deserialize(reader: &mut R) -> io::Result { diff --git a/src/fastfield/reader.rs b/src/fastfield/reader.rs index 94f187344..7c01d0a8f 100644 --- a/src/fastfield/reader.rs +++ b/src/fastfield/reader.rs @@ -128,14 +128,18 @@ impl From> for U64FastFieldReader { } directory .open_read(path) - .chain_err(|| "Failed to open the file") - .and_then(|source| FastFieldsReader::from_source(source) - .chain_err(|| "Failed to read the file.")) - .and_then(|ff_readers| ff_readers - .open_reader(field) - .ok_or_else(|| {"Failed to find the requested field".into() })) + .chain_err(|| "Failed to open the file") + .and_then(|source| { + FastFieldsReader::from_source(source) + .chain_err(|| "Failed to read the file.") + }) + .and_then(|ff_readers| { + ff_readers + .open_reader(field) + .ok_or_else(|| "Failed to find the requested field".into()) + }) .expect("This should never happen, please report.") - + } } diff --git a/src/termdict/merger.rs b/src/termdict/merger.rs index 6967be9c7..4689e0673 100644 --- a/src/termdict/merger.rs +++ b/src/termdict/merger.rs @@ -48,7 +48,6 @@ impl<'a, V> Ord for HeapItem<'a, V> /// - the term /// - a slice with the ordinal of the segments containing /// the terms. -#[allow(should_implement_trait)] pub struct TermMerger<'a, V> where V: 'a + BinarySerializable + Default { @@ -131,6 +130,7 @@ impl<'a, V> TermMerger<'a, V> } /// Iterates through terms + #[allow(should_implement_trait)] pub fn next(&mut self) -> Option> { if self.advance() { Some(Term::wrap(self.current_streamers[0].streamer.key()))