Add a way to define a deadline for inline changes (#61)

This commit is contained in:
Armin Ronacher 2024-03-28 21:52:56 +01:00 committed by GitHub
parent ace8f34a27
commit 75d40b041b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 4 deletions

View file

@ -7,7 +7,7 @@ use crate::types::{Algorithm, Change, ChangeTag, DiffOp, DiffTag};
use crate::{capture_diff_deadline, get_diff_ratio};
use std::ops::Index;
use std::time::{Duration, Instant};
use std::time::Instant;
use super::utils::upper_seq_ratio;
@ -195,11 +195,11 @@ impl<'s, T: DiffableStr + ?Sized> fmt::Display for InlineChange<'s, T> {
}
const MIN_RATIO: f32 = 0.5;
const TIMEOUT_MS: u64 = 500;
pub(crate) fn iter_inline_changes<'x, 'diff, 'old, 'new, 'bufs, T>(
diff: &'diff TextDiff<'old, 'new, 'bufs, T>,
op: &DiffOp,
deadline: Option<Instant>,
) -> impl Iterator<Item = InlineChange<'x, T>> + 'diff
where
T: DiffableStr + ?Sized,
@ -231,7 +231,7 @@ where
0..old_lookup.len(),
&new_lookup,
0..new_lookup.len(),
Some(Instant::now() + Duration::from_millis(TIMEOUT_MS)),
deadline,
);
if get_diff_ratio(&ops, old_lookup.len(), new_lookup.len()) < MIN_RATIO {