mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 08:41:06 +01:00
Some minor efficiency fixes. (#3835)
This doesn't move the needle too much, but cleans some things up. It let me see an underlying issue that I'll try to fix next.
This commit is contained in:
@@ -103,7 +103,7 @@ auto FileTestAutoupdater::CheckLine::RemapLineNumbers(
|
||||
}
|
||||
|
||||
auto FileTestAutoupdater::GetFileAndLineNumber(
|
||||
llvm::DenseMap<llvm::StringRef, int> file_to_number_map,
|
||||
const llvm::DenseMap<llvm::StringRef, int>& file_to_number_map,
|
||||
int default_file_number, const std::string& check_line)
|
||||
-> FileAndLineNumber {
|
||||
for (const auto& replacement : line_number_replacements_) {
|
||||
@@ -157,18 +157,29 @@ auto FileTestAutoupdater::BuildCheckLines(llvm::StringRef output,
|
||||
}
|
||||
|
||||
// `{{` and `[[` are escaped as a regex matcher.
|
||||
RE2 double_brace_re(R"(\{\{)");
|
||||
RE2 double_square_bracket_re(R"(\[\[)");
|
||||
static RE2 double_brace_re(R"(\{\{)");
|
||||
static RE2 double_square_bracket_re(R"(\[\[)");
|
||||
// End-of-line whitespace is replaced with a regex matcher to make it visible.
|
||||
RE2 end_of_line_whitespace_re(R"((\s+)$)");
|
||||
static RE2 end_of_line_whitespace_re(R"((\s+)$)");
|
||||
|
||||
// The default file number for when no specific file is found.
|
||||
int default_file_number = 0;
|
||||
|
||||
llvm::SmallVector<CheckLine> check_lines;
|
||||
for (const auto& line : lines) {
|
||||
std::string check_line = llvm::formatv("// CHECK:{0}:{1}{2}", label,
|
||||
line.empty() ? "" : " ", line);
|
||||
// This code is relatively hot in our testing, and because when testing it
|
||||
// isn't run with an optimizer we benefit from making it use simple
|
||||
// constructs. For this reason, we avoid `llvm::formatv` and similar tools.
|
||||
std::string check_line;
|
||||
check_line.reserve(line.size() + strlen(label) + strlen("// CHECK:: "));
|
||||
check_line.append("// CHECK:");
|
||||
check_line.append(label);
|
||||
check_line.append(":");
|
||||
if (!line.empty()) {
|
||||
check_line.append(" ");
|
||||
check_line.append(line);
|
||||
}
|
||||
|
||||
RE2::Replace(&check_line, double_brace_re, R"({{\\{\\{}})");
|
||||
RE2::Replace(&check_line, double_square_bracket_re, R"({{\\[\\[}})");
|
||||
RE2::Replace(&check_line, end_of_line_whitespace_re, R"({{\1}})");
|
||||
|
||||
@@ -139,7 +139,7 @@ class FileTestAutoupdater {
|
||||
// Looks for the patterns in the line. Returns the first match, or defaulted
|
||||
// information if not found.
|
||||
auto GetFileAndLineNumber(
|
||||
llvm::DenseMap<llvm::StringRef, int> file_to_number_map,
|
||||
const llvm::DenseMap<llvm::StringRef, int>& file_to_number_map,
|
||||
int default_file_number, const std::string& check_line)
|
||||
-> FileAndLineNumber;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user