WGUNDERWOOD / tex-fmt

An extremely fast LaTeX formatter written in Rust
MIT License
265 stars 20 forks source link

Remove quadratic complexity from `find_comment_index` #23

Closed ZetrextJG closed 2 months ago

ZetrextJG commented 2 months ago

When calling the .nth() method on the Chars type ( Char iterator ) one will consume the iterator up to the n-th item and return that item if found https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.nth.

The means that the previous implementation has quadratic complexity in the case of a multi-character line. This one is linear and will iterator over the line at most one time.

All the previous functionality has been accounted for. The tests pass.

WGUNDERWOOD commented 2 months ago

Thanks for this!