Optimize static error test file parsing.

For some reason, the regexp to strip off multitest comments was very
slow. On a couple of co_19 tests with pathologically long lines, it
would hang practically forever. Even on shorter lines, it was noticeably
slow. This fixes that.

Change-Id: I04f2894f474dcc593e982dd691945421396274a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193222
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
This commit is contained in:
Robert Nystrom 2021-03-30 16:58:11 +00:00 committed by commit-bot@chromium.org
parent fa243e700a
commit 5cc772b8aa

View file

@ -392,9 +392,6 @@ class _ErrorExpectationParser {
/// are part of it.
static final _errorMessageRestRegExp = RegExp(r"^\s*//\s*(.*)");
/// Matches the multitest marker and yields the preceding content.
final _stripMultitestRegExp = RegExp(r"(.*)//#");
final List<String> _lines;
final List<StaticError> _errors = [];
int _currentLine = 0;
@ -524,9 +521,9 @@ class _ErrorExpectationParser {
var line = _lines[_currentLine + offset];
// Strip off any multitest marker.
var multitestMatch = _stripMultitestRegExp.firstMatch(line);
if (multitestMatch != null) {
line = multitestMatch.group(1).trimRight();
var index = line.indexOf("//#");
if (index != -1) {
line = line.substring(0, index).trimRight();
}
return line;