From 479dd9c35a21bd9beccf886d18cee8847b71a3ff Mon Sep 17 00:00:00 2001 From: Ihor Andrianov Date: Sun, 23 Mar 2025 21:11:35 +0200 Subject: [PATCH] clippy --- core/json/json_operations.rs | 10 +++++----- core/json/jsonb.rs | 38 ++++++++++++++++-------------------- core/json/mod.rs | 26 ++++++++++++------------ 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/core/json/json_operations.rs b/core/json/json_operations.rs index 2d221173c..7700c2f6f 100644 --- a/core/json/json_operations.rs +++ b/core/json/json_operations.rs @@ -167,7 +167,7 @@ pub fn json_remove(args: &[OwnedValue]) -> crate::Result { let el_type = json.is_valid()?; - json_string_to_db_type(json, el_type, OutputVariant::AsString) + json_string_to_db_type(json, el_type, OutputVariant::String) } pub fn jsonb_remove(args: &[OwnedValue]) -> crate::Result { @@ -206,7 +206,7 @@ pub fn json_replace(args: &[OwnedValue]) -> crate::Result { let el_type = json.is_valid()?; - json_string_to_db_type(json, el_type, super::OutputVariant::AsString) + json_string_to_db_type(json, el_type, super::OutputVariant::String) } pub fn jsonb_replace(args: &[OwnedValue]) -> crate::Result { @@ -228,7 +228,7 @@ pub fn jsonb_replace(args: &[OwnedValue]) -> crate::Result { let el_type = json.is_valid()?; - json_string_to_db_type(json, el_type, OutputVariant::AsBinary) + json_string_to_db_type(json, el_type, OutputVariant::Binary) } pub fn json_insert(args: &[OwnedValue]) -> crate::Result { @@ -250,7 +250,7 @@ pub fn json_insert(args: &[OwnedValue]) -> crate::Result { let el_type = json.is_valid()?; - json_string_to_db_type(json, el_type, OutputVariant::AsString) + json_string_to_db_type(json, el_type, OutputVariant::String) } pub fn jsonb_insert(args: &[OwnedValue]) -> crate::Result { @@ -272,7 +272,7 @@ pub fn jsonb_insert(args: &[OwnedValue]) -> crate::Result { let el_type = json.is_valid()?; - json_string_to_db_type(json, el_type, OutputVariant::AsBinary) + json_string_to_db_type(json, el_type, OutputVariant::Binary) } #[cfg(test)] diff --git a/core/json/jsonb.rs b/core/json/jsonb.rs index 2220e7d35..2567d40c0 100644 --- a/core/json/jsonb.rs +++ b/core/json/jsonb.rs @@ -414,25 +414,21 @@ impl PathOperation for DeleteOperation { 0 }; json.update_parent_references(stack, target.delta + delta + h_delta)?; + } else if let JsonLocationKind::ObjectProperty(key_idx) = target.field_key_index { + let value_idx = target.field_value_index; + let (JsonbHeader(_, value_size), value_header_size) = json.read_header(value_idx)?; + let (JsonbHeader(_, key_size), key_header_size) = json.read_header(key_idx)?; + let delta = 0 - (value_header_size + value_size + key_size + key_header_size) as isize; + + let end_pos = key_idx + value_header_size + value_size + key_size + key_header_size; + json.data.drain(key_idx..end_pos); + + json.update_parent_references(stack, delta + target.delta)?; } else { - if let JsonLocationKind::ObjectProperty(key_idx) = target.field_key_index { - let value_idx = target.field_value_index; - let (JsonbHeader(_, value_size), value_header_size) = - json.read_header(value_idx)?; - let (JsonbHeader(_, key_size), key_header_size) = json.read_header(key_idx)?; - let delta = - 0 - (value_header_size + value_size + key_size + key_header_size) as isize; - - let end_pos = key_idx + value_header_size + value_size + key_size + key_header_size; - json.data.drain(key_idx..end_pos); - - json.update_parent_references(stack, delta + target.delta)?; - } else { - let nul = JsonbHeader::make_null().into_bytes(); - let nul_bytes = nul.as_bytes(); - json.data.clear(); - json.data.extend_from_slice(nul_bytes); - } + let nul = JsonbHeader::make_null().into_bytes(); + let nul_bytes = nul.as_bytes(); + json.data.clear(); + json.data.extend_from_slice(nul_bytes); } Ok(()) @@ -1302,7 +1298,7 @@ impl Jsonb { b'"' | b'\'' => { pos = self.deserialize_string(input, pos)?; } - c if (b'0'..=b'9').contains(&c) + c if c.is_ascii_digit() || c == b'-' || c == b'+' || c == b'.' @@ -1987,7 +1983,7 @@ impl Jsonb { Ok(stack) } - pub fn operate_on_path<'a, T>(&mut self, path: &JsonPath, operation: &'a mut T) -> Result<()> + pub fn operate_on_path(&mut self, path: &JsonPath, operation: &mut T) -> Result<()> where T: PathOperation, { @@ -2501,7 +2497,7 @@ impl Jsonb { } }; - return Err(LimboError::ParseError("Not found".to_string())); + Err(LimboError::ParseError("Not found".to_string())) } fn skip_element(&self, mut pos: usize) -> Result { diff --git a/core/json/mod.rs b/core/json/mod.rs index 08555df88..2f45f8cc1 100644 --- a/core/json/mod.rs +++ b/core/json/mod.rs @@ -43,9 +43,9 @@ enum Conv { } enum OutputVariant { - AsElementType, - AsBinary, - AsString, + ElementType, + Binary, + String, } pub fn get_json(json_value: &OwnedValue, indent: Option<&str>) -> crate::Result { @@ -170,7 +170,7 @@ pub fn json_array(values: &[OwnedValue]) -> crate::Result { } json.finalize_unsafe(ElementType::ARRAY)?; - json_string_to_db_type(json, ElementType::ARRAY, OutputVariant::AsElementType) + json_string_to_db_type(json, ElementType::ARRAY, OutputVariant::ElementType) } pub fn jsonb_array(values: &[OwnedValue]) -> crate::Result { @@ -185,7 +185,7 @@ pub fn jsonb_array(values: &[OwnedValue]) -> crate::Result { } json.finalize_unsafe(ElementType::ARRAY)?; - json_string_to_db_type(json, ElementType::ARRAY, OutputVariant::AsBinary) + json_string_to_db_type(json, ElementType::ARRAY, OutputVariant::Binary) } pub fn json_array_length( @@ -231,7 +231,7 @@ pub fn json_set(args: &[OwnedValue]) -> crate::Result { let el_type = json.is_valid()?; - json_string_to_db_type(json, el_type, OutputVariant::AsString) + json_string_to_db_type(json, el_type, OutputVariant::String) } /// Implements the -> operator. Always returns a proper JSON value. @@ -279,7 +279,7 @@ pub fn json_arrow_shift_extract( Ok(json_string_to_db_type( extracted, element_type, - OutputVariant::AsElementType, + OutputVariant::ElementType, )?) } else { Ok(OwnedValue::Null) @@ -302,7 +302,7 @@ pub fn json_extract(value: &OwnedValue, paths: &[OwnedValue]) -> crate::Result crate::Result< } let (json, element_type) = jsonb_extract_internal(value, paths)?; - let result = json_string_to_db_type(json, element_type, OutputVariant::AsElementType)?; + let result = json_string_to_db_type(json, element_type, OutputVariant::ElementType)?; Ok(result) } @@ -377,13 +377,13 @@ fn json_string_to_db_type( flag: OutputVariant, ) -> crate::Result { let mut json_string = json.to_string()?; - if matches!(flag, OutputVariant::AsBinary) { + if matches!(flag, OutputVariant::Binary) { return Ok(OwnedValue::Blob(Rc::new(json.data()))); } match element_type { ElementType::ARRAY | ElementType::OBJECT => Ok(OwnedValue::Text(Text::json(json_string))), ElementType::TEXT | ElementType::TEXT5 | ElementType::TEXTJ | ElementType::TEXTRAW => { - if matches!(flag, OutputVariant::AsElementType) { + if matches!(flag, OutputVariant::ElementType) { json_string.remove(json_string.len() - 1); json_string.remove(0); Ok(OwnedValue::Text(Text { @@ -568,7 +568,7 @@ pub fn json_object(values: &[OwnedValue]) -> crate::Result { json.finalize_unsafe(ElementType::OBJECT)?; - json_string_to_db_type(json, ElementType::OBJECT, OutputVariant::AsString) + json_string_to_db_type(json, ElementType::OBJECT, OutputVariant::String) } pub fn jsonb_object(values: &[OwnedValue]) -> crate::Result { @@ -589,7 +589,7 @@ pub fn jsonb_object(values: &[OwnedValue]) -> crate::Result { json.finalize_unsafe(ElementType::OBJECT)?; - json_string_to_db_type(json, ElementType::OBJECT, OutputVariant::AsBinary) + json_string_to_db_type(json, ElementType::OBJECT, OutputVariant::Binary) } pub fn is_json_valid(json_value: &OwnedValue) -> OwnedValue {