Find-in-Page: Cached Flat Buffer with Lazy Invalidation
This commit introduces CachedMatchFinder, a new class wrapping TextIterator that maintains a flattened text buffer of all visible page content and caches find-in-page results. Cache invalidation is gated on domTreeVersion and styleRecalcCount. The architecture shifts from per-query full DOM traversal with a windowed SearchBuffer to a single cached flat buffer with unbounded ICU search.
Before: After:
findNext() findNext()
└─► TextIterator (full DOM walk) └─► CachedMatchFinder
└─► SearchBuffer (windowed) ├─[valid]─► cached matches
└─► match range └─[stale]─► rebuild buffer + ICU search
Cache validity: domTreeVersion == saved && styleRecalcCount == saved
Shadow DOM traversal behavior is controlled by find options: flat-tree mode can traverse across shadow boundaries, while DoNotTraverseFlatTree mode respects scope isolation.
Significance
Unlike SearchBuffer's windowed approach, CachedMatchFinder allocates a single flat buffer for the entire document — pathologically large pages could cause large allocations, and the offset-to-BoundaryPoint mapping introduces a new class of potential off-by-one errors.