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])
| 415 | /// are a subsequence of side B's, then B is a superset that contains |
| 416 | /// everything A has plus more — B subsumes A. |
| 417 | fn is_token_subsequence(sub: &[MergeToken], sup: &[MergeToken]) -> bool { |
| 418 | if sub.is_empty() { |
| 419 | return true; |
| 420 | } |
| 421 | if sub.len() > sup.len() { |
| 422 | return false; |
| 423 | } |
| 424 | let mut si = 0; // index into sub |
| 425 | for token in sup { |
| 426 | if token == &sub[si] { |
| 427 | si += 1; |
| 428 | if si == sub.len() { |
| 429 | return true; |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | false |
| 434 | } |
| 435 | |
| 436 | // =========================================================================== |
| 437 | // Backward-compatible single-type-parameter wrapper |