Skip syntax highlighting for long lines (#2165)

* Skip highlighting for long lines

* Run cargo fmt, update changelog
This commit is contained in:
Keith Hall 2022-05-04 08:59:24 +03:00 committed by GitHub
parent 5114c0189d
commit b5294f1cb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 3 deletions

View File

@ -12,6 +12,7 @@
## Other
- Include info about custom assets in `--diagnostics` if used. See #2107, #2144 (@Enselic)
- Skip syntax highlighting on long lines (> 16384 chars) to help improve performance. See #2165 (@keith-hall)
## Syntaxes

View File

@ -445,9 +445,18 @@ impl<'a> Printer for InteractivePrinter<'a> {
return Ok(());
}
};
highlighter_from_set
.highlighter
.highlight(&line, highlighter_from_set.syntax_set)
// skip syntax highlighting on long lines
if line.len() > 1024 * 16 {
let mut empty = highlighter_from_set
.highlighter
.highlight(&"\n", highlighter_from_set.syntax_set);
empty[0].1 = line.as_ref();
empty
} else {
highlighter_from_set
.highlighter
.highlight(&line, highlighter_from_set.syntax_set)
}
};
if out_of_range {

3
tests/examples/longline.json vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long