@@ -29,18 +29,14 @@ impl<'a> Position<'a> {
29
29
debug_assert_eq ! ( exit. kind, Kind :: Exit , "expected `exit` event" ) ;
30
30
let mut enter_index = index - 1 ;
31
31
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 {
42
33
enter_index -= 1 ;
43
34
}
35
+
36
+ Position {
37
+ start : & events[ enter_index] . point ,
38
+ end : & exit. point ,
39
+ }
44
40
}
45
41
46
42
/// Turn a position into indices.
@@ -122,17 +118,17 @@ impl<'a> Slice<'a> {
122
118
///
123
119
/// Supports virtual spaces.
124
120
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.
125
125
let mut string = String :: with_capacity ( self . len ( ) ) ;
126
126
let mut index = self . before ;
127
127
while index > 0 {
128
128
string. push ( ' ' ) ;
129
129
index -= 1 ;
130
130
}
131
131
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.
136
132
string
137
133
}
138
134
}
0 commit comments