Skip to content

Commit 5366f79

Browse files
committed
Improve config performance on degenerate cases
Before fe997c8, we only advanced `i` on `key_value_pair` success. After, we always advance it. This prevents the loop break from properly activating, causing O(n^2) (at least) parse behavior as we eat a bit and then process the remaining input as a `value_impl` until we hit an error, and then repeat.
1 parent e208362 commit 5366f79

File tree

1 file changed

+4
-1
lines changed
  • gix-config/src/parse/nom

1 file changed

+4
-1
lines changed

gix-config/src/parse/nom/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ fn section<'i>(
121121
dispatch(Event::Newline(Cow::Borrowed(v.as_bstr())));
122122
}
123123

124-
let _ = key_value_pair(i, node, dispatch);
124+
let before_key = i.checkpoint();
125+
if key_value_pair(i, node, dispatch).is_err() {
126+
i.reset(before_key);
127+
}
125128

126129
if let Some(comment) = opt(comment).parse_next(i)? {
127130
dispatch(Event::Comment(comment));

0 commit comments

Comments
 (0)