Add default timeout for inline highlighting
This commit is contained in:
parent
56f50a0c87
commit
28bfd4698a
2 changed files with 6 additions and 2 deletions
|
|
@ -8,6 +8,7 @@ All notable changes to similar are documented here.
|
||||||
* Small performance improvments by adding an early opt-out for and inline highlighting.
|
* Small performance improvments by adding an early opt-out for and inline highlighting.
|
||||||
* Added deadlines to all diffing algorithms to bail early.
|
* Added deadlines to all diffing algorithms to bail early.
|
||||||
* Deprecated slice diffing methods in the individual algorithm modules.
|
* Deprecated slice diffing methods in the individual algorithm modules.
|
||||||
|
- Use a default timeout for the inline highlighting feature.
|
||||||
|
|
||||||
## 1.2.2
|
## 1.2.2
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,10 @@ use std::fmt;
|
||||||
|
|
||||||
use crate::text::{DiffableStr, TextDiff};
|
use crate::text::{DiffableStr, TextDiff};
|
||||||
use crate::types::{Algorithm, Change, ChangeTag, DiffOp, DiffTag};
|
use crate::types::{Algorithm, Change, ChangeTag, DiffOp, DiffTag};
|
||||||
use crate::{capture_diff, get_diff_ratio};
|
use crate::{capture_diff_deadline, get_diff_ratio};
|
||||||
|
|
||||||
use std::ops::Index;
|
use std::ops::Index;
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use super::utils::upper_seq_ratio;
|
use super::utils::upper_seq_ratio;
|
||||||
|
|
||||||
|
|
@ -187,6 +188,7 @@ impl<'s, T: DiffableStr + ?Sized> fmt::Display for InlineChange<'s, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
const MIN_RATIO: f32 = 0.5;
|
const MIN_RATIO: f32 = 0.5;
|
||||||
|
const TIMEOUT_MS: u64 = 500;
|
||||||
|
|
||||||
pub(crate) fn iter_inline_changes<'x, 'diff, 'old, 'new, 'bufs, T>(
|
pub(crate) fn iter_inline_changes<'x, 'diff, 'old, 'new, 'bufs, T>(
|
||||||
diff: &'diff TextDiff<'old, 'new, 'bufs, T>,
|
diff: &'diff TextDiff<'old, 'new, 'bufs, T>,
|
||||||
|
|
@ -216,12 +218,13 @@ where
|
||||||
let old_lookup = MultiLookup::new(old_slices);
|
let old_lookup = MultiLookup::new(old_slices);
|
||||||
let new_lookup = MultiLookup::new(new_slices);
|
let new_lookup = MultiLookup::new(new_slices);
|
||||||
|
|
||||||
let ops = capture_diff(
|
let ops = capture_diff_deadline(
|
||||||
Algorithm::Patience,
|
Algorithm::Patience,
|
||||||
&old_lookup,
|
&old_lookup,
|
||||||
0..old_lookup.len(),
|
0..old_lookup.len(),
|
||||||
&new_lookup,
|
&new_lookup,
|
||||||
0..new_lookup.len(),
|
0..new_lookup.len(),
|
||||||
|
Some(Instant::now() + Duration::from_millis(TIMEOUT_MS)),
|
||||||
);
|
);
|
||||||
|
|
||||||
if get_diff_ratio(&ops, old_lookup.len(), new_lookup.len()) < MIN_RATIO {
|
if get_diff_ratio(&ops, old_lookup.len(), new_lookup.len()) < MIN_RATIO {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue