Skip to content

Commit b553df1

Browse files
committed
Refactor some code to improve coverage
1 parent 246063f commit b553df1

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/util/slice.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,14 @@ impl<'a> Position<'a> {
2929
debug_assert_eq!(exit.kind, Kind::Exit, "expected `exit` event");
3030
let mut enter_index = index - 1;
3131

32-
loop {
33-
let enter = &events[enter_index];
34-
if enter.kind == Kind::Enter && enter.name == exit.name {
35-
let position = Position {
36-
start: &enter.point,
37-
end: &exit.point,
38-
};
39-
return position;
40-
}
41-
32+
while events[enter_index].kind != Kind::Enter || events[enter_index].name != exit.name {
4233
enter_index -= 1;
4334
}
35+
36+
Position {
37+
start: &events[enter_index].point,
38+
end: &exit.point,
39+
}
4440
}
4541

4642
/// Turn a position into indices.
@@ -122,17 +118,17 @@ impl<'a> Slice<'a> {
122118
///
123119
/// Supports virtual spaces.
124120
pub fn serialize(&self) -> String {
121+
debug_assert_eq!(self.after, 0, "expected no trailing vs");
122+
// If the above ever starts erroring, handle the same as `self.before`
123+
// above but with `self.after`.
124+
// It’d currently be unused code.
125125
let mut string = String::with_capacity(self.len());
126126
let mut index = self.before;
127127
while index > 0 {
128128
string.push(' ');
129129
index -= 1;
130130
}
131131
string.push_str(self.as_str());
132-
debug_assert_eq!(self.after, 0, "expected no trailing vs");
133-
// If the above ever starts erroring, handle the same as `self.before`
134-
// above but with `self.after`.
135-
// It’d currently be unused code.
136132
string
137133
}
138134
}

0 commit comments

Comments
 (0)