From 00f78d6b5a0642db042a33d3e660b4a4177f5d33 Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 13 Apr 2022 11:47:20 +0200 Subject: [PATCH] Apply code suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Renault --- json-depth-checker/Cargo.toml | 2 +- json-depth-checker/src/lib.rs | 6 +++--- milli/src/update/index_documents/transform.rs | 18 ++++++++---------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/json-depth-checker/Cargo.toml b/json-depth-checker/Cargo.toml index 9c386a383..d608a49dc 100644 --- a/json-depth-checker/Cargo.toml +++ b/json-depth-checker/Cargo.toml @@ -13,4 +13,4 @@ criterion = "0.3" [[bench]] name = "depth" -harness = false \ No newline at end of file +harness = false diff --git a/json-depth-checker/src/lib.rs b/json-depth-checker/src/lib.rs index 0d423aadb..3d0f28af8 100644 --- a/json-depth-checker/src/lib.rs +++ b/json-depth-checker/src/lib.rs @@ -3,9 +3,9 @@ use serde_json::Value; /// Your json MUST BE valid and generated by `serde_json::to_vec` before being /// sent in this function. This function is DUMB and FAST but makes a lot of /// asumption about the way `serde_json` will generate its input. -/// Will returns `true` if the json contains an object, an array of array -/// or an array containing an object. -/// Returns `false` for everything else. +/// +/// Will return `true` if the JSON contains an object, an array of array +/// or an array containing an object. Returns `false` for everything else. pub fn should_flatten_from_unchecked_slice(json: &[u8]) -> bool { if json.is_empty() { return false; diff --git a/milli/src/update/index_documents/transform.rs b/milli/src/update/index_documents/transform.rs index e94eb170b..c215872ca 100644 --- a/milli/src/update/index_documents/transform.rs +++ b/milli/src/update/index_documents/transform.rs @@ -286,10 +286,9 @@ impl<'a, 'i> Transform<'a, 'i> { })?; self.original_sorter.insert(&docid.to_be_bytes(), base_obkv)?; - if let Some(buffer) = self.flatten_from_fields_ids_map(KvReader::new(&base_obkv))? { - self.flattened_sorter.insert(docid.to_be_bytes(), &buffer)?; - } else { - self.flattened_sorter.insert(docid.to_be_bytes(), base_obkv)?; + match self.flatten_from_fields_ids_map(KvReader::new(&base_obkv))? { + Some(buffer) => self.flattened_sorter.insert(docid.to_be_bytes(), &buffer)?, + None => self.flattened_sorter.insert(docid.to_be_bytes(), base_obkv)?, } } else { self.new_documents_ids.insert(docid); @@ -302,12 +301,11 @@ impl<'a, 'i> Transform<'a, 'i> { if let Some(flatten) = flattened_document { self.flattened_sorter.insert(docid.to_be_bytes(), &flatten)?; } else { - if let Some(buffer) = - self.flatten_from_fields_ids_map(KvReader::new(&obkv_buffer))? - { - self.flattened_sorter.insert(docid.to_be_bytes(), &buffer)?; - } else { - self.flattened_sorter.insert(docid.to_be_bytes(), obkv_buffer.clone())?; + match self.flatten_from_fields_ids_map(KvReader::new(&obkv_buffer))? { + Some(buffer) => self.flattened_sorter.insert(docid.to_be_bytes(), &buffer)?, + None => { + self.flattened_sorter.insert(docid.to_be_bytes(), obkv_buffer.clone())? + } } }