xpointer(string-range(...)) matched the search string at every position of each node's value and re-allocated the whole needle window per position, an O(text * needle) search and a denial-of-service vector on a long node value with a near-matching needle. Replace it with a linear-time Knuth-Morris-Pratt search (failure function built once, since the needle is fixed across nodes). Matches are unchanged: same non-overlapping, left-to-right occurrences, same offset/length. A near-matching needle over a 16000-character node drops from about 0.18 s to about 0.002 s (~100x), now linear. |
||
|---|---|---|
| .. | ||
| Pointer.swift | ||
| PointerRange.swift | ||
| XPointerError.swift | ||