Skip to content

Commit 3eb8699

Browse files
committed
Fixed clippy lints
1 parent 989b395 commit 3eb8699

6 files changed

Lines changed: 153 additions & 133 deletions

File tree

asyncgit/src/graph/buffer.rs

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Buffer {
4343
self.mergers.push(alias);
4444
}
4545

46-
pub fn update(&mut self, new_chunk: Chunk) {
46+
pub fn update(&mut self, new_chunk: &Chunk) {
4747
self.pending_delta.clear();
4848

4949
let mut empty_lanes: Vec<usize> = self
@@ -56,17 +56,15 @@ impl Buffer {
5656
// sort descending so we can pop the lowest index first
5757
empty_lanes.sort_unstable_by(|a, b| b.cmp(a));
5858

59-
let mut found_idx = None;
60-
if new_chunk.alias.is_some() {
61-
for (i, c) in self.current.iter().enumerate() {
62-
if let Some(c) = c {
63-
if c.parent_a == new_chunk.alias {
64-
found_idx = Some(i);
65-
break;
66-
}
67-
}
68-
}
69-
}
59+
let found_idx = if new_chunk.alias.is_some() {
60+
self.current.iter().enumerate().find_map(|(i, c)| {
61+
c.as_ref().and_then(|c| {
62+
(c.parent_a == new_chunk.alias).then_some(i)
63+
})
64+
})
65+
} else {
66+
None
67+
};
7068

7169
if let Some(idx) = found_idx {
7270
self.record_replace(idx, Some(new_chunk.clone()));
@@ -89,20 +87,18 @@ impl Buffer {
8987
}
9088

9189
if let Some(mut c) = self.current[index].clone() {
92-
let mut changed = false;
93-
94-
if new_chunk.alias.is_some()
95-
&& c.parent_a == new_chunk.alias
96-
{
97-
c.parent_a = None;
98-
changed = true;
99-
}
100-
if new_chunk.alias.is_some()
101-
&& c.parent_b == new_chunk.alias
102-
{
103-
c.parent_b = None;
104-
changed = true;
105-
}
90+
let changed = new_chunk.alias.is_some_and(|alias| {
91+
let mut changed = false;
92+
if c.parent_a == Some(alias) {
93+
c.parent_a = None;
94+
changed = true;
95+
}
96+
if c.parent_b == Some(alias) {
97+
c.parent_b = None;
98+
changed = true;
99+
}
100+
changed
101+
});
106102

107103
if changed {
108104
if c.parent_a.is_none() && c.parent_b.is_none() {
@@ -117,7 +113,7 @@ impl Buffer {
117113
while let Some(alias) = self.mergers.pop() {
118114
if let Some(index) = self.current.iter().position(|c| {
119115
c.as_ref()
120-
.map_or(false, |chunk| chunk.alias == Some(alias))
116+
.is_some_and(|chunk| chunk.alias == Some(alias))
121117
}) {
122118
if let Some(mut c) = self.current[index].clone() {
123119
let parent_b = c.parent_b;
@@ -146,14 +142,8 @@ impl Buffer {
146142
}
147143
}
148144

149-
loop {
150-
if let Some(last) = self.current.last() {
151-
if last.is_none() {
152-
self.record_remove(self.current.len() - 1);
153-
continue;
154-
}
155-
}
156-
break;
145+
while self.current.last().is_some_and(Option::is_none) {
146+
self.record_remove(self.current.len() - 1);
157147
}
158148

159149
let delta = Delta(self.pending_delta.clone());
@@ -193,12 +183,11 @@ impl Buffer {
193183
start: usize,
194184
end: usize,
195185
) -> Vec<Vector<Option<Chunk>>> {
196-
let (current_index, mut state) = self
197-
.checkpoints
198-
.range(..=start)
199-
.next_back()
200-
.map(|(&i, s)| (Some(i), s.clone()))
201-
.unwrap_or((None, Vector::new()));
186+
let (current_index, mut state) =
187+
self.checkpoints.range(..=start).next_back().map_or_else(
188+
|| (None, Vector::new()),
189+
|(&i, s)| (Some(i), s.clone()),
190+
);
202191

203192
let mut history =
204193
Vec::with_capacity(end.saturating_sub(start) + 1);
@@ -209,11 +198,11 @@ impl Buffer {
209198
}
210199
}
211200

212-
let loop_start = current_index.map(|i| i + 1).unwrap_or(0);
201+
let loop_start = current_index.map_or(0, |i| i + 1);
213202

214203
for delta_index in loop_start..=end {
215204
if let Some(delta) = self.deltas.get(delta_index) {
216-
self.apply_delta_to_state(&mut state, delta);
205+
Self::apply_delta_to_state(&mut state, delta);
217206

218207
if delta_index >= start {
219208
history.push(state.clone());
@@ -227,14 +216,13 @@ impl Buffer {
227216
}
228217

229218
fn apply_delta_to_state(
230-
&self,
231219
state: &mut Vector<Option<Chunk>>,
232220
delta: &Delta,
233221
) {
234222
for op in &delta.0 {
235223
match op {
236224
DeltaOp::Insert { index, item } => {
237-
state.insert(*index, item.clone())
225+
state.insert(*index, item.clone());
238226
}
239227
DeltaOp::Remove { index } => {
240228
state.remove(*index);

asyncgit/src/graph/chunk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[derive(Clone, Debug, PartialEq)]
1+
#[derive(Clone, Debug, PartialEq, Eq)]
22
pub enum Markers {
33
Uncommitted,
44
Commit,

asyncgit/src/graph/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub mod walker;
55

66
pub use walker::GraphWalker;
77

8-
#[derive(Clone, Debug, PartialEq)]
8+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
99
pub enum ConnType {
1010
Vertical,
1111
VerticalDotted,
@@ -41,11 +41,11 @@ pub struct GraphRow {
4141

4242
/// Connections emitted per lane:
4343
/// None = empty space
44-
/// Some((ConnType, color_index)) = draw this connector in this color
44+
/// Some((ConnType, `color_index`)) = draw this connector in this color
4545
pub lanes: Vec<Option<(ConnType, usize)>>,
4646

4747
/// Horizontal merge bridge: if this commit merges rightward,
48-
/// (from_lane, to_lane) — the span to draw ─ ╭ ╮ across
48+
/// (`from_lane`, `to_lane`) — the span to draw ─ ╭ ╮ across
4949
pub merge_bridge: Option<(usize, usize)>,
5050

5151
/// Horizontal branch bridges: if this commit spawns branches,

asyncgit/src/graph/oids.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub struct Oids {
55
/// alias
66
pub ids: Vec<CommitId>,
77

8-
/// CommitId to alias
8+
/// `CommitId` to alias
99
pub aliases: HashMap<CommitId, u32>,
1010
}
1111

@@ -27,7 +27,8 @@ impl Oids {
2727
if let Some(&alias) = self.aliases.get(id) {
2828
return alias;
2929
}
30-
let alias = self.ids.len() as u32;
30+
let alias =
31+
u32::try_from(self.ids.len()).expect("too many oids");
3132
self.ids.push(*id);
3233
self.aliases.insert(*id, alias);
3334
alias

0 commit comments

Comments
 (0)