From 1d67012aa59adcfcb3362e11f0e1d421613bd7be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Tue, 1 Jan 2019 01:40:20 +0100 Subject: [PATCH] chore: Clean up some database functions --- src/database/mod.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/database/mod.rs b/src/database/mod.rs index 20f20d544..6e03dd44d 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -38,29 +38,25 @@ where D: Deref fn retrieve_data_index(snapshot: &Snapshot) -> Result> where D: Deref { - match snapshot.get(DATA_INDEX)? { + let index = match snapshot.get(DATA_INDEX)? { Some(vector) => { - let bytes_len = vector.as_ref().len(); - let bytes = Arc::new(vector.as_ref().to_vec()); - Ok(Index::from_shared_bytes(bytes, 0, bytes_len)?) + let bytes = vector.as_ref().to_vec(); + Index::from_bytes(bytes)? }, - None => Ok(Index::default()), - } + None => Index::default(), + }; + + Ok(index) } fn merge_indexes(key: &[u8], existing: Option<&[u8]>, operands: &mut MergeOperands) -> Vec { assert_eq!(key, DATA_INDEX, "The merge operator only supports \"data-index\" merging"); let mut index: Option = None; - for bytes in existing.into_iter().chain(operands) { - let bytes_len = bytes.len(); - let bytes = Arc::new(bytes.to_vec()); - let operand = Index::from_shared_bytes(bytes, 0, bytes_len); - let operand = operand.expect("BUG: could not deserialize index"); - + let operand = Index::from_bytes(bytes.to_vec()).unwrap(); let merged = match index { - Some(ref index) => index.merge(&operand).expect("BUG: could not merge index"), + Some(ref index) => index.merge(&operand).unwrap(), None => operand, };