mirror of
https://github.com/block/buzz.git
synced 2026-11-30 21:21:48 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user