From 202e69b7e0145643886d9747ad316b1beaa027d2 Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Sat, 15 Apr 2017 19:41:14 +0900 Subject: [PATCH] BUGFIX the thing observed on windows --- src/datastruct/stream_dictionary.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/datastruct/stream_dictionary.rs b/src/datastruct/stream_dictionary.rs index 942ffe5fe..965defff3 100644 --- a/src/datastruct/stream_dictionary.rs +++ b/src/datastruct/stream_dictionary.rs @@ -252,7 +252,8 @@ fn get_offset<'a, V, P: Fn(&[u8])->bool>(predicate: P, mut streamer: StreamDicti where V: 'a + BinarySerializable + Clone + Default { // let mut streamer = stream_dictionary.stream_before(target_key.as_ref()); let mut prev: &[u8] = streamer.cursor; - let mut prev_data: Vec = vec!(); + + let mut prev_data: Vec = streamer.current_key.clone(); while let Some((iter_key, _)) = streamer.next() { if !predicate(iter_key) { return (prev.as_ptr() as usize, prev_data, streamer.cursor.as_ptr() as usize); @@ -326,7 +327,7 @@ impl<'a, V: BinarySerializable> StreamDictionaryStreamer<'a, V> { } let common_length: usize = VInt::deserialize(&mut self.cursor).unwrap().0 as usize; let new_length: usize = common_length + VInt::deserialize(&mut self.cursor).unwrap().0 as usize; - self.current_key.reserve(new_length); // TODO check if we can do better. + self.current_key.reserve(new_length); unsafe { self.current_key.set_len(new_length); } @@ -383,6 +384,8 @@ mod test { stream_dictionary.get(key.as_bytes()); } + + #[test] fn test_stream_range() { let ids: Vec<_> = (0u32..10_000u32) @@ -396,7 +399,7 @@ mod test { stream_dictionary_builder.finish().unwrap() }; let source = ReadOnlySource::from(buffer); - + let stream_dictionary: StreamDictionary = StreamDictionary::from_source(source).unwrap(); { for i in (0..20).chain((BLOCK_SIZE - 10..BLOCK_SIZE + 10)) { @@ -447,7 +450,7 @@ mod test { } } } + } - }