diff --git a/src/lib.rs b/src/lib.rs index 6e9e9de..e9636b1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -178,6 +178,7 @@ impl PathTree { } /// Inserts a part path-value to the tree and returns the id. + #[allow(clippy::missing_panics_doc)] #[must_use] pub fn insert(&mut self, path: &str, value: T) -> usize { let mut node = &mut self.node; diff --git a/src/node.rs b/src/node.rs index 16487da..16bd58d 100644 --- a/src/node.rs +++ b/src/node.rs @@ -387,6 +387,9 @@ impl Node { self._find(0, bytes, &mut ranges).map(|t| (t, ranges)) } + #[allow(clippy::only_used_in_recursion)] + #[allow(clippy::too_many_lines)] + #[inline] pub fn _remove(&mut self, mut start: usize, mut bytes: &[u8]) -> Option { let mut m = bytes.len(); match &self.key { @@ -411,24 +414,22 @@ impl Node { if m == 0 { return self.value.take(); - } else { + } else if let Some(id) = self.nodes0.as_mut().and_then(|nodes| { // static - if let Some(id) = self.nodes0.as_mut().and_then(|nodes| { - nodes - .binary_search_by(|node| match &node.key { - Key::String(s) => { - // s[0].cmp(&bytes[0]) - // opt! - // lets `/` at end - compare(s[0], bytes[0]) - } - Key::Parameter(_) => unreachable!(), - }) - .ok() - .and_then(|i| nodes[i]._remove(start, bytes)) - }) { - return Some(id); - } + nodes + .binary_search_by(|node| match &node.key { + Key::String(s) => { + // s[0].cmp(&bytes[0]) + // opt! + // lets `/` at end + compare(s[0], bytes[0]) + } + Key::Parameter(_) => unreachable!(), + }) + .ok() + .and_then(|i| nodes[i]._remove(start, bytes)) + }) { + return Some(id); } // parameter @@ -582,10 +583,8 @@ impl Node { return self.value.take(); } } else { - if self.nodes0.is_none() && self.nodes1.is_none() { - if self.value.is_some() { - return self.value.take(); - } + if self.nodes0.is_none() && self.nodes1.is_none() && self.value.is_some() { + return self.value.take(); } // static