Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use saturating substraction to calculate Line ranges #1891

Merged
merged 3 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
## Bugfixes

- Python syntax highlighting no longer suffers from abysmal performance in specific scenarios. See #1688 (@keith-hall)
- First line not shown in diff context. See #1891 (@divagant-martian)

## Performance

Expand Down
3 changes: 2 additions & 1 deletion src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ impl<'b> Controller<'b> {
if let Some(line_changes) = line_changes {
for &line in line_changes.keys() {
let line = line as usize;
line_ranges.push(LineRange::new(line - context, line + context));
line_ranges
.push(LineRange::new(line.saturating_sub(context), line + context));
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/output/changes.snapshot.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
+ /// A rectangle. First line is changed to prevent a regression of #1869
struct Rectangle {
width: u32,
height: u32,
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/output/changes_grid.snapshot.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
──┬─────────────────────────────────────────────────────────────────────────────
+ │ /// A rectangle. First line is changed to prevent a regression of #1869
│ struct Rectangle {
│ width: u32,
│ height: u32,
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/output/changes_grid_header.snapshot.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
──┬─────────────────────────────────────────────────────────────────────────────
│ File: sample.rs
──┼─────────────────────────────────────────────────────────────────────────────
+ │ /// A rectangle. First line is changed to prevent a regression of #1869
│ struct Rectangle {
│ width: u32,
│ height: u32,
Expand Down
45 changes: 23 additions & 22 deletions tests/snapshots/output/changes_grid_header_numbers.snapshot.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
───────┬────────────────────────────────────────────────────────────────────────
│ File: sample.rs
───────┼────────────────────────────────────────────────────────────────────────
1 │ struct Rectangle {
2 │ width: u32,
3 │ height: u32,
4 │ }
5 │
6 _ │ fn main() {
7 │ let rect1 = Rectangle { width: 30, height: 50 };
8 │
9 │ println!(
10 ~ │ "The perimeter of the rectangle is {} pixels.",
11 ~ │ perimeter(&rect1)
12 │ );
13 + │ println!(r#"This line contains invalid utf8: "�����"#;
14 │ }
15 │
16 │ fn area(rectangle: &Rectangle) -> u32 {
17 │ rectangle.width * rectangle.height
18 │ }
19 + │
20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
21 + │ (rectangle.width + rectangle.height) * 2
22 + │ }
1 + │ /// A rectangle. First line is changed to prevent a regression of #1869
2 │ struct Rectangle {
3 │ width: u32,
4 │ height: u32,
5 │ }
6 │
7 _ │ fn main() {
8 │ let rect1 = Rectangle { width: 30, height: 50 };
9 │
10 │ println!(
11 ~ │ "The perimeter of the rectangle is {} pixels.",
12 ~ │ perimeter(&rect1)
13 │ );
14 + │ println!(r#"This line contains invalid utf8: "�����"#;
15 │ }
16 │
17 │ fn area(rectangle: &Rectangle) -> u32 {
18 │ rectangle.width * rectangle.height
19 │ }
20 + │
21 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
22 + │ (rectangle.width + rectangle.height) * 2
23 + │ }
───────┴────────────────────────────────────────────────────────────────────────
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
───────┬────────────────────────────────────────────────────────────────────────
│ File: sample.rs
───────┼────────────────────────────────────────────────────────────────────────
1 │ struct Rectangle {
2 │ width: u32,
3 │ height: u32,
4 │ }
5 │
6 _ │ fn main() {
7 │ let rect1 = Rectangle { width: 30, height: 50 };
8 │
9 │ println!(
10 ~ │ "The perimeter of the rectangle is {} pixels.",
11 ~ │ perimeter(&rect1)
12 │ );
13 + │ println!(r#"This line contains invalid utf8: "�����"#;
14 │ }
15 │
16 │ fn area(rectangle: &Rectangle) -> u32 {
17 │ rectangle.width * rectangle.height
18 │ }
19 + │
20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
21 + │ (rectangle.width + rectangle.height) * 2
22 + │ }
1 + │ /// A rectangle. First line is changed to prevent a regression of #1869
2 │ struct Rectangle {
3 │ width: u32,
4 │ height: u32,
5 │ }
6 │
7 _ │ fn main() {
8 │ let rect1 = Rectangle { width: 30, height: 50 };
9 │
10 │ println!(
11 ~ │ "The perimeter of the rectangle is {} pixels.",
12 ~ │ perimeter(&rect1)
13 │ );
14 + │ println!(r#"This line contains invalid utf8: "�����"#;
15 │ }
16 │
17 │ fn area(rectangle: &Rectangle) -> u32 {
18 │ rectangle.width * rectangle.height
19 │ }
20 + │
21 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
22 + │ (rectangle.width + rectangle.height) * 2
23 + │ }
───────┴────────────────────────────────────────────────────────────────────────
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
──┬─────────────────────────────────────────────────────────────────────────────
│ File: sample.rs
──┼─────────────────────────────────────────────────────────────────────────────
+ │ /// A rectangle. First line is changed to prevent a regression of #1869
│ struct Rectangle {
│ width: u32,
│ height: u32,
Expand Down
45 changes: 23 additions & 22 deletions tests/snapshots/output/changes_grid_numbers.snapshot.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
───────┬────────────────────────────────────────────────────────────────────────
1 │ struct Rectangle {
2 │ width: u32,
3 │ height: u32,
4 │ }
5 │
6 _ │ fn main() {
7 │ let rect1 = Rectangle { width: 30, height: 50 };
8 │
9 │ println!(
10 ~ │ "The perimeter of the rectangle is {} pixels.",
11 ~ │ perimeter(&rect1)
12 │ );
13 + │ println!(r#"This line contains invalid utf8: "�����"#;
14 │ }
15 │
16 │ fn area(rectangle: &Rectangle) -> u32 {
17 │ rectangle.width * rectangle.height
18 │ }
19 + │
20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
21 + │ (rectangle.width + rectangle.height) * 2
22 + │ }
1 + │ /// A rectangle. First line is changed to prevent a regression of #1869
2 │ struct Rectangle {
3 │ width: u32,
4 │ height: u32,
5 │ }
6 │
7 _ │ fn main() {
8 │ let rect1 = Rectangle { width: 30, height: 50 };
9 │
10 │ println!(
11 ~ │ "The perimeter of the rectangle is {} pixels.",
12 ~ │ perimeter(&rect1)
13 │ );
14 + │ println!(r#"This line contains invalid utf8: "�����"#;
15 │ }
16 │
17 │ fn area(rectangle: &Rectangle) -> u32 {
18 │ rectangle.width * rectangle.height
19 │ }
20 + │
21 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
22 + │ (rectangle.width + rectangle.height) * 2
23 + │ }
───────┴────────────────────────────────────────────────────────────────────────
45 changes: 23 additions & 22 deletions tests/snapshots/output/changes_grid_numbers_rule.snapshot.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
───────┬────────────────────────────────────────────────────────────────────────
1 │ struct Rectangle {
2 │ width: u32,
3 │ height: u32,
4 │ }
5 │
6 _ │ fn main() {
7 │ let rect1 = Rectangle { width: 30, height: 50 };
8 │
9 │ println!(
10 ~ │ "The perimeter of the rectangle is {} pixels.",
11 ~ │ perimeter(&rect1)
12 │ );
13 + │ println!(r#"This line contains invalid utf8: "�����"#;
14 │ }
15 │
16 │ fn area(rectangle: &Rectangle) -> u32 {
17 │ rectangle.width * rectangle.height
18 │ }
19 + │
20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
21 + │ (rectangle.width + rectangle.height) * 2
22 + │ }
1 + │ /// A rectangle. First line is changed to prevent a regression of #1869
2 │ struct Rectangle {
3 │ width: u32,
4 │ height: u32,
5 │ }
6 │
7 _ │ fn main() {
8 │ let rect1 = Rectangle { width: 30, height: 50 };
9 │
10 │ println!(
11 ~ │ "The perimeter of the rectangle is {} pixels.",
12 ~ │ perimeter(&rect1)
13 │ );
14 + │ println!(r#"This line contains invalid utf8: "�����"#;
15 │ }
16 │
17 │ fn area(rectangle: &Rectangle) -> u32 {
18 │ rectangle.width * rectangle.height
19 │ }
20 + │
21 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
22 + │ (rectangle.width + rectangle.height) * 2
23 + │ }
───────┴────────────────────────────────────────────────────────────────────────
1 change: 1 addition & 0 deletions tests/snapshots/output/changes_grid_rule.snapshot.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
──┬─────────────────────────────────────────────────────────────────────────────
+ │ /// A rectangle. First line is changed to prevent a regression of #1869
│ struct Rectangle {
│ width: u32,
│ height: u32,
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/output/changes_header.snapshot.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
File: sample.rs
+ /// A rectangle. First line is changed to prevent a regression of #1869
struct Rectangle {
width: u32,
height: u32,
Expand Down
45 changes: 23 additions & 22 deletions tests/snapshots/output/changes_header_numbers.snapshot.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
File: sample.rs
1 struct Rectangle {
2 width: u32,
3 height: u32,
4 }
5
6 _ fn main() {
7 let rect1 = Rectangle { width: 30, height: 50 };
8
9 println!(
10 ~ "The perimeter of the rectangle is {} pixels.",
11 ~ perimeter(&rect1)
12 );
13 + println!(r#"This line contains invalid utf8: "�����"#;
14 }
15
16 fn area(rectangle: &Rectangle) -> u32 {
17 rectangle.width * rectangle.height
18 }
19 +
20 + fn perimeter(rectangle: &Rectangle) -> u32 {
21 + (rectangle.width + rectangle.height) * 2
22 + }
1 + /// A rectangle. First line is changed to prevent a regression of #1869
2 struct Rectangle {
3 width: u32,
4 height: u32,
5 }
6
7 _ fn main() {
8 let rect1 = Rectangle { width: 30, height: 50 };
9
10 println!(
11 ~ "The perimeter of the rectangle is {} pixels.",
12 ~ perimeter(&rect1)
13 );
14 + println!(r#"This line contains invalid utf8: "�����"#;
15 }
16
17 fn area(rectangle: &Rectangle) -> u32 {
18 rectangle.width * rectangle.height
19 }
20 +
21 + fn perimeter(rectangle: &Rectangle) -> u32 {
22 + (rectangle.width + rectangle.height) * 2
23 + }
45 changes: 23 additions & 22 deletions tests/snapshots/output/changes_header_numbers_rule.snapshot.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
File: sample.rs
1 struct Rectangle {
2 width: u32,
3 height: u32,
4 }
5
6 _ fn main() {
7 let rect1 = Rectangle { width: 30, height: 50 };
8
9 println!(
10 ~ "The perimeter of the rectangle is {} pixels.",
11 ~ perimeter(&rect1)
12 );
13 + println!(r#"This line contains invalid utf8: "�����"#;
14 }
15
16 fn area(rectangle: &Rectangle) -> u32 {
17 rectangle.width * rectangle.height
18 }
19 +
20 + fn perimeter(rectangle: &Rectangle) -> u32 {
21 + (rectangle.width + rectangle.height) * 2
22 + }
1 + /// A rectangle. First line is changed to prevent a regression of #1869
2 struct Rectangle {
3 width: u32,
4 height: u32,
5 }
6
7 _ fn main() {
8 let rect1 = Rectangle { width: 30, height: 50 };
9
10 println!(
11 ~ "The perimeter of the rectangle is {} pixels.",
12 ~ perimeter(&rect1)
13 );
14 + println!(r#"This line contains invalid utf8: "�����"#;
15 }
16
17 fn area(rectangle: &Rectangle) -> u32 {
18 rectangle.width * rectangle.height
19 }
20 +
21 + fn perimeter(rectangle: &Rectangle) -> u32 {
22 + (rectangle.width + rectangle.height) * 2
23 + }
1 change: 1 addition & 0 deletions tests/snapshots/output/changes_header_rule.snapshot.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
File: sample.rs
+ /// A rectangle. First line is changed to prevent a regression of #1869
struct Rectangle {
width: u32,
height: u32,
Expand Down
45 changes: 23 additions & 22 deletions tests/snapshots/output/changes_numbers.snapshot.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
1 struct Rectangle {
2 width: u32,
3 height: u32,
4 }
5
6 _ fn main() {
7 let rect1 = Rectangle { width: 30, height: 50 };
8
9 println!(
10 ~ "The perimeter of the rectangle is {} pixels.",
11 ~ perimeter(&rect1)
12 );
13 + println!(r#"This line contains invalid utf8: "�����"#;
14 }
15
16 fn area(rectangle: &Rectangle) -> u32 {
17 rectangle.width * rectangle.height
18 }
19 +
20 + fn perimeter(rectangle: &Rectangle) -> u32 {
21 + (rectangle.width + rectangle.height) * 2
22 + }
1 + /// A rectangle. First line is changed to prevent a regression of #1869
2 struct Rectangle {
3 width: u32,
4 height: u32,
5 }
6
7 _ fn main() {
8 let rect1 = Rectangle { width: 30, height: 50 };
9
10 println!(
11 ~ "The perimeter of the rectangle is {} pixels.",
12 ~ perimeter(&rect1)
13 );
14 + println!(r#"This line contains invalid utf8: "�����"#;
15 }
16
17 fn area(rectangle: &Rectangle) -> u32 {
18 rectangle.width * rectangle.height
19 }
20 +
21 + fn perimeter(rectangle: &Rectangle) -> u32 {
22 + (rectangle.width + rectangle.height) * 2
23 + }
Loading