Skip to content

Commit 7bd4cbd

Browse files
committed
Improve dedentation performance
1 parent d811e79 commit 7bd4cbd

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ tex-fmt is over a thousand times faster than latexindent.
174174

175175
| **Files** | **Lines** | **Size** | **tex-fmt** | **latexindent** | **latexindent -m** |
176176
| --- | --- | --- | --- | --- | --- |
177-
| 49 | 94k | 3.5M | **0.065s** | 99s [x1523] | 132s [x2031] |
177+
| 49 | 94k | 3.5M | **0.055s** | 99s [x1800] | 132s [x2400] |
178178

179179
## Contribution
180180

src/indent.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ fn get_back(line: &str, pattern: &Pattern) -> i8 {
6868
let mut back: i8 = 0;
6969
let mut cumul: i8 = 0;
7070

71-
// delimiters
72-
for c in line.chars() {
73-
cumul -= i8::from(OPENS.contains(&c));
74-
cumul += i8::from(CLOSES.contains(&c));
75-
back = max(cumul, back);
71+
// Dedent delimiters
72+
// Check first whether there are any closing delimiters
73+
if CLOSES.iter().any(|c| line.contains(*c)) {
74+
for c in line.chars() {
75+
cumul -= i8::from(OPENS.contains(&c));
76+
cumul += i8::from(CLOSES.contains(&c));
77+
back = max(cumul, back);
78+
}
7679
}
7780

7881
// other environments get single indents

0 commit comments

Comments
 (0)