summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2022-10-16 10:17:01 +0200
committerJoel Rosdahl <joel@rosdahl.net>2022-10-16 10:50:10 +0200
commit3ec0d4ec961cb0c67ff1603b83a6026d9f3abbb5 (patch)
treef5356ad812eda01a5a59c2290645a7c7b3ecc79e
parent4e1c615602eff875366a3374442a1e96937858a0 (diff)
downloadccache-3ec0d4ec961cb0c67ff1603b83a6026d9f3abbb5.tar.gz
refactor: Avoid an extra data copy when rewriting stdout
-rw-r--r--src/ccache.cpp10
-rw-r--r--src/core/MsvcShowIncludesOutput.cpp6
2 files changed, 9 insertions, 7 deletions
diff --git a/src/ccache.cpp b/src/ccache.cpp
index 30868567..861bc5b1 100644
--- a/src/ccache.cpp
+++ b/src/ccache.cpp
@@ -950,7 +950,7 @@ rewrite_stdout_from_compiler(const Context& ctx, util::Bytes&& stdout_data)
using Mode = Tokenizer::Mode;
using IncludeDelimiter = Tokenizer::IncludeDelimiter;
if (!stdout_data.empty()) {
- std::string new_stdout_text;
+ util::Bytes new_stdout_data;
for (const auto line : Tokenizer(util::to_string_view(stdout_data),
"\n",
Mode::include_empty,
@@ -973,12 +973,14 @@ rewrite_stdout_from_compiler(const Context& ctx, util::Bytes&& stdout_data)
ctx, Util::normalize_concrete_absolute_path(abs_inc_path));
std::string line_with_rel_inc =
util::replace_first(orig_line, abs_inc_path, rel_inc_path);
- new_stdout_text.append(line_with_rel_inc);
+ new_stdout_data.insert(new_stdout_data.begin(),
+ line_with_rel_inc.data(),
+ line_with_rel_inc.size());
} else {
- new_stdout_text.append(line.data(), line.length());
+ new_stdout_data.insert(new_stdout_data.end(), line.data(), line.size());
}
}
- return util::Bytes(new_stdout_text.data(), new_stdout_text.size());
+ return new_stdout_data;
} else {
return std::move(stdout_data);
}
diff --git a/src/core/MsvcShowIncludesOutput.cpp b/src/core/MsvcShowIncludesOutput.cpp
index 5289eadc..311a1bcb 100644
--- a/src/core/MsvcShowIncludesOutput.cpp
+++ b/src/core/MsvcShowIncludesOutput.cpp
@@ -61,16 +61,16 @@ strip_includes(const Context& ctx, util::Bytes&& stdout_data)
return std::move(stdout_data);
}
- std::string new_stdout_text;
+ util::Bytes new_stdout_data;
for (const auto line : Tokenizer(util::to_string_view(stdout_data),
"\n",
Mode::include_empty,
IncludeDelimiter::yes)) {
if (!util::starts_with(line, ctx.config.msvc_dep_prefix())) {
- new_stdout_text.append(line.data(), line.length());
+ new_stdout_data.insert(new_stdout_data.end(), line.data(), line.size());
}
}
- return util::Bytes(new_stdout_text.data(), new_stdout_text.size());
+ return new_stdout_data;
}
} // namespace core::MsvcShowIncludesOutput