Check whether `sub`'s tokens are a subsequence of `sup`'s tokens. A subsequence means every token in `sub` appears in `sup` in the same order, possibly with extra tokens interspersed in `sup`. This is used for concurrent insertion resolution: if side A's tokens are a subsequence of side B's, then B is a superset that contains everything A has plus more — B subsumes A.
(sub: &[MergeToken], sup: &[MergeToken])
| 386 | /// are a subsequence of side B's, then B is a superset that contains |
| 387 | /// everything A has plus more — B subsumes A. |
| 388 | fn is_token_subsequence(sub: &[MergeToken], sup: &[MergeToken]) -> bool { |
| 389 | if sub.is_empty() { |
| 390 | return true; |
| 391 | } |
| 392 | if sub.len() > sup.len() { |
| 393 | return false; |
| 394 | } |
| 395 | let mut si = 0; // index into sub |
| 396 | for token in sup { |
| 397 | if token == &sub[si] { |
| 398 | si += 1; |
| 399 | if si == sub.len() { |
| 400 | return true; |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | false |
| 405 | } |
| 406 | |
| 407 | // =========================================================================== |
| 408 | // Backward-compatible single-type-parameter wrapper |