Compute replacements during a single ForEach traversal and collect only changed values before mutating the document, avoiding array allocations and second lookups for unchanged text. Stop scanning after the last targeted user position.