fuzzers: Don't pointlessly format diagnostics

Fuzzers like to generate silly long source, and formatting large spans of these can take considerable time.
Only format the diagnostic if it is going to be displayed.

Significantly speeds up some fuzzing tests, fixing some timeouts.

Also add a minor optimization to the formatter repeat() implementation.

Fixed: chromium:1230313
Change-Id: Ib1f6ac0b31010f86cb7f4e1432dc703ecbe52cb0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/58841
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
Ben Clayton
2021-07-20 14:39:50 +00:00
committed by Tint LUCI CQ
parent efceb83536
commit b29396e472
4 changed files with 30 additions and 21 deletions

View File

@@ -15,6 +15,7 @@
#include "src/diagnostic/formatter.h"
#include <algorithm>
#include <iterator>
#include <vector>
#include "src/diagnostic/diagnostic.h"
@@ -96,9 +97,7 @@ struct Formatter::State {
/// @param c the character to print `n` times
/// @param n the number of times to print character `c`
void repeat(char c, size_t n) {
while (n-- > 0) {
stream << c;
}
std::fill_n(std::ostream_iterator<char>(stream), n, c);
}
private: