mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 10:21:04 +01:00
Switch FileTest to use StringRefs instead of files. (#2885)
In explorer, we already support parsing a string_view, so use that. In toolchain, we need to build support, probably using vfs, so that's a todo. bazel test //explorer:file_test --runs_per_test=5 - branch: Stats over 250 runs: max = 18.3s, min = 5.2s, avg = 11.2s, dev = 2.9s - trunk: Stats over 250 runs: max = 22.3s, min = 5.9s, avg = 12.1s, dev = 2.8s Not a dramatic improvement, but maybe more effective long-term, and this'd been requested on #2876
This commit is contained in:
@@ -38,7 +38,7 @@ static auto PrintTimingOnExit(TraceStream* trace_stream, const char* label,
|
||||
}
|
||||
|
||||
static auto ParseAndExecuteHelper(std::function<ErrorOr<AST>(Arena*)> parse,
|
||||
const std::string& prelude_path,
|
||||
std::string_view prelude_path,
|
||||
Nonnull<TraceStream*> trace_stream,
|
||||
Nonnull<llvm::raw_ostream*> print_stream)
|
||||
-> ErrorOr<int> {
|
||||
@@ -90,8 +90,8 @@ static auto ParseAndExecuteHelper(std::function<ErrorOr<AST>(Arena*)> parse,
|
||||
});
|
||||
}
|
||||
|
||||
auto ParseAndExecuteFile(const std::string& prelude_path,
|
||||
const std::string& input_file_name, bool parser_debug,
|
||||
auto ParseAndExecuteFile(std::string_view prelude_path,
|
||||
std::string_view input_file_name, bool parser_debug,
|
||||
Nonnull<TraceStream*> trace_stream,
|
||||
Nonnull<llvm::raw_ostream*> print_stream)
|
||||
-> ErrorOr<int> {
|
||||
@@ -101,15 +101,15 @@ auto ParseAndExecuteFile(const std::string& prelude_path,
|
||||
return ParseAndExecuteHelper(parse, prelude_path, trace_stream, print_stream);
|
||||
}
|
||||
|
||||
auto ParseAndExecute(const std::string& prelude_path, const std::string& source)
|
||||
-> ErrorOr<int> {
|
||||
auto ParseAndExecute(std::string_view prelude_path,
|
||||
std::string_view input_file_name,
|
||||
std::string_view file_contents, bool parser_debug,
|
||||
Nonnull<TraceStream*> trace_stream,
|
||||
Nonnull<llvm::raw_ostream*> print_stream) -> ErrorOr<int> {
|
||||
auto parse = [&](Arena* arena) {
|
||||
return ParseFromString(arena, "test.carbon", source,
|
||||
/*parser_debug=*/false);
|
||||
return ParseFromString(arena, input_file_name, file_contents, parser_debug);
|
||||
};
|
||||
TraceStream trace_stream;
|
||||
return ParseAndExecuteHelper(parse, prelude_path, &trace_stream,
|
||||
&llvm::nulls());
|
||||
return ParseAndExecuteHelper(parse, prelude_path, trace_stream, print_stream);
|
||||
}
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
Reference in New Issue
Block a user