Mercurial > public > mercurial-scm > hg
diff rust/hg-core/src/revlog/node.rs @ 44973:26114bd6ec60
rust: do a clippy pass
This is the result of running `cargo clippy` on hg-core/hg-cpython and fixing
the lints that do not require too much code churn (and would warrant a separate
commit/complete refactor) and only come from our code (a lot of warnings in
hg-cpython come from `rust-cpython`).
Most of those were good lints, two of them was the linter not being smart
enough (or compiler to get up to `clippy`'s level depending on how you see it).
Maybe in the future we could have `clippy` be part of the CI.
Differential Revision: https://phab.mercurial-scm.org/D8635
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 15 Jun 2020 18:26:40 +0200 |
parents | 166349510398 |
children | b0d6309ff50c |
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/node.rs Mon Jun 15 15:14:16 2020 -0400 +++ b/rust/hg-core/src/revlog/node.rs Mon Jun 15 18:26:40 2020 +0200 @@ -208,6 +208,10 @@ } } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + pub fn is_prefix_of(&self, node: &Node) -> bool { if self.is_odd { let buf = self.buf; @@ -242,13 +246,13 @@ } else { buf.len() }; - for i in 0..until { - if buf[i] != node.data[i] { - if buf[i] & 0xf0 == node.data[i] & 0xf0 { - return Some(2 * i + 1); + for (i, item) in buf.iter().enumerate().take(until) { + if *item != node.data[i] { + return if *item & 0xf0 == node.data[i] & 0xf0 { + Some(2 * i + 1) } else { - return Some(2 * i); - } + Some(2 * i) + }; } } if self.is_odd && buf[until] & 0xf0 != node.data[until] & 0xf0 {