perf(mobile): bound the kept error text scan

Find the first line break with firstMatch rather than indexOf, which
retries the pattern at every position, and replace a first line over
twice the limit before removing identity hashes. Note in ADR 0007 that
closing punctuation after a ? or # in a kept line is read as prose.

Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
Tom Brow
2026-11-20 13:38:26 -08:00
parent 1b6135c0ca
commit 6a0d9d4e4d
3 changed files with 7 additions and 6 deletions

View File

@@ -146,11 +146,11 @@ abstract final class DiagnosticFilter {
/// line, or the lines after the first, usually quote other text, such as a
/// response body or a wrapped error.
static String _keptText(String text) {
final lineEnd = text.indexOf(_lineBreak);
final line = (lineEnd < 0 ? text : text.substring(0, lineEnd)).replaceAll(
_identityHash,
'',
);
final lineEnd = _lineBreak.firstMatch(text)?.start ?? text.length;
// Replaced without scanning: only a line made mostly of identity hashes
// could come under the limit after their removal.
if (lineEnd > 2 * _keptTextLimit) return removedText;
final line = text.substring(0, lineEnd).replaceAll(_identityHash, '');
return line.length > _keptTextLimit || line.contains(_mayHoldUrl)
? removedText
: line;