From 277766f55efc7ba37fbaa3a9f86ba36e9adb94f0 Mon Sep 17 00:00:00 2001 From: Ali Tofigh Date: Fri, 15 Jul 2022 00:44:02 +0200 Subject: [PATCH] adopt absl::string_view in logging/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:13579 Change-Id: Ibc5fa7842d52321d61cc4cdd4770635af737ddff Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/267170 Reviewed-by: Björn Terelius Commit-Queue: Ali Tofigh Reviewed-by: Erik Språng Cr-Commit-Position: refs/heads/main@{#37533} --- logging/BUILD.gn | 9 ++++++++- .../rtc_event_log/encoder/delta_encoding.cc | 15 +++++++------- .../rtc_event_log/encoder/delta_encoding.h | 3 ++- .../rtc_event_log/events/logged_rtp_rtcp.h | 7 ++++--- .../events/rtc_event_field_encoding_parser.h | 20 ++++++++++++------- .../rtc_event_field_encoding_unittest.cc | 5 +++-- .../rtc_event_log/rtc_event_log2rtp_dump.cc | 5 +++-- logging/rtc_event_log/rtc_event_log_impl.cc | 13 ++++++++---- logging/rtc_event_log/rtc_event_log_impl.h | 7 ++++--- logging/rtc_event_log/rtc_event_log_parser.cc | 7 ++++--- logging/rtc_event_log/rtc_event_log_parser.h | 7 ++++--- .../rtc_event_log_unittest_helper.cc | 3 ++- logging/rtc_event_log/rtc_stream_config.cc | 4 +++- logging/rtc_event_log/rtc_stream_config.h | 3 ++- test/logging/BUILD.gn | 5 ++++- test/logging/file_log_writer.cc | 12 ++++++----- test/logging/file_log_writer.h | 8 +++++--- test/logging/log_writer.cc | 8 +++++--- test/logging/log_writer.h | 9 ++++++--- test/logging/memory_log_writer.cc | 6 ++++-- 20 files changed, 100 insertions(+), 56 deletions(-) diff --git a/logging/BUILD.gn b/logging/BUILD.gn index 25985ebd15..8905c4aced 100644 --- a/logging/BUILD.gn +++ b/logging/BUILD.gn @@ -71,6 +71,7 @@ rtc_library("rtc_stream_config") { "../api:rtp_headers", "../api:rtp_parameters", ] + absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_library("rtc_event_pacing") { @@ -376,7 +377,10 @@ if (rtc_enable_protobuf) { "../rtc_base:timeutils", "../rtc_base/system:no_unique_address", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] + absl_deps = [ + "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/types:optional", + ] } } @@ -459,6 +463,7 @@ if (rtc_enable_protobuf) { ] absl_deps = [ "//third_party/abseil-cpp/absl/memory", + "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", ] } @@ -523,6 +528,7 @@ if (rtc_enable_protobuf) { ] absl_deps = [ "//third_party/abseil-cpp/absl/memory", + "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", ] } @@ -545,6 +551,7 @@ if (rtc_enable_protobuf) { "//third_party/abseil-cpp/absl/flags:parse", "//third_party/abseil-cpp/absl/flags:usage", "//third_party/abseil-cpp/absl/memory", + "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", ] } diff --git a/logging/rtc_event_log/encoder/delta_encoding.cc b/logging/rtc_event_log/encoder/delta_encoding.cc index 3a2bee1d31..c80424574c 100644 --- a/logging/rtc_event_log/encoder/delta_encoding.cc +++ b/logging/rtc_event_log/encoder/delta_encoding.cc @@ -16,6 +16,7 @@ #include #include "absl/memory/memory.h" +#include "absl/strings/string_view.h" #include "logging/rtc_event_log/encoder/bit_writer.h" #include "logging/rtc_event_log/encoder/var_int.h" #include "rtc_base/bit_buffer.h" @@ -554,7 +555,7 @@ class FixedLengthDeltaDecoder final { // bitstream. Note that this does NOT imply that stream is valid, and will // be decoded successfully. It DOES imply that all other decoder classes // will fail to decode this input, though. - static bool IsSuitableDecoderFor(const std::string& input); + static bool IsSuitableDecoderFor(absl::string_view input); // Assuming that `input` is the result of fixed-size delta-encoding // that took place with the same value to `base` and over `num_of_deltas` @@ -562,7 +563,7 @@ class FixedLengthDeltaDecoder final { // If an error occurs (can happen if `input` is corrupt), an empty // vector will be returned. static std::vector> DecodeDeltas( - const std::string& input, + absl::string_view input, absl::optional base, size_t num_of_deltas); @@ -579,7 +580,7 @@ class FixedLengthDeltaDecoder final { // the entire stream is free of error. Rather, only the encoding header is // examined and guaranteed. static std::unique_ptr Create( - const std::string& input, + absl::string_view input, absl::optional base, size_t num_of_deltas); @@ -624,7 +625,7 @@ class FixedLengthDeltaDecoder final { const size_t num_of_deltas_; }; -bool FixedLengthDeltaDecoder::IsSuitableDecoderFor(const std::string& input) { +bool FixedLengthDeltaDecoder::IsSuitableDecoderFor(absl::string_view input) { BitstreamReader reader(input); uint64_t encoding_type_bits = reader.ReadBits(kBitsInHeaderForEncodingType); if (!reader.Ok()) { @@ -639,7 +640,7 @@ bool FixedLengthDeltaDecoder::IsSuitableDecoderFor(const std::string& input) { } std::vector> FixedLengthDeltaDecoder::DecodeDeltas( - const std::string& input, + absl::string_view input, absl::optional base, size_t num_of_deltas) { auto decoder = FixedLengthDeltaDecoder::Create(input, base, num_of_deltas); @@ -651,7 +652,7 @@ std::vector> FixedLengthDeltaDecoder::DecodeDeltas( } std::unique_ptr FixedLengthDeltaDecoder::Create( - const std::string& input, + absl::string_view input, absl::optional base, size_t num_of_deltas) { BitstreamReader reader(input); @@ -804,7 +805,7 @@ std::string EncodeDeltas(absl::optional base, } std::vector> DecodeDeltas( - const std::string& input, + absl::string_view input, absl::optional base, size_t num_of_deltas) { RTC_DCHECK_GT(num_of_deltas, 0); // Allows empty vector to indicate error. diff --git a/logging/rtc_event_log/encoder/delta_encoding.h b/logging/rtc_event_log/encoder/delta_encoding.h index 614012acd3..779cdc6b2f 100644 --- a/logging/rtc_event_log/encoder/delta_encoding.h +++ b/logging/rtc_event_log/encoder/delta_encoding.h @@ -17,6 +17,7 @@ #include #include +#include "absl/strings/string_view.h" #include "absl/types/optional.h" namespace webrtc { @@ -39,7 +40,7 @@ std::string EncodeDeltas(absl::optional base, // vector, which signals an error. // TODO(eladalon): Split into optional and non-optional variants (efficiency). std::vector> DecodeDeltas( - const std::string& input, + absl::string_view input, absl::optional base, size_t num_of_deltas); diff --git a/logging/rtc_event_log/events/logged_rtp_rtcp.h b/logging/rtc_event_log/events/logged_rtp_rtcp.h index 053a16371d..00689a0a16 100644 --- a/logging/rtc_event_log/events/logged_rtp_rtcp.h +++ b/logging/rtc_event_log/events/logged_rtp_rtcp.h @@ -14,6 +14,7 @@ #include #include +#include "absl/strings/string_view.h" #include "api/rtp_headers.h" #include "api/units/timestamp.h" #include "modules/rtp_rtcp/source/rtcp_packet/bye.h" @@ -79,7 +80,7 @@ struct LoggedRtpPacketOutgoing { struct LoggedRtcpPacket { LoggedRtcpPacket(Timestamp timestamp, const std::vector& packet) : timestamp(timestamp), raw_data(packet) {} - LoggedRtcpPacket(Timestamp timestamp, const std::string& packet) + LoggedRtcpPacket(Timestamp timestamp, absl::string_view packet) : timestamp(timestamp), raw_data(packet.size()) { memcpy(raw_data.data(), packet.data(), packet.size()); } @@ -100,7 +101,7 @@ struct LoggedRtcpPacketIncoming { LoggedRtcpPacketIncoming(Timestamp timestamp, const std::vector& packet) : rtcp(timestamp, packet) {} - LoggedRtcpPacketIncoming(Timestamp timestamp, const std::string& packet) + LoggedRtcpPacketIncoming(Timestamp timestamp, absl::string_view packet) : rtcp(timestamp, packet) {} int64_t log_time_us() const { return rtcp.timestamp.us(); } @@ -114,7 +115,7 @@ struct LoggedRtcpPacketOutgoing { LoggedRtcpPacketOutgoing(Timestamp timestamp, const std::vector& packet) : rtcp(timestamp, packet) {} - LoggedRtcpPacketOutgoing(Timestamp timestamp, const std::string& packet) + LoggedRtcpPacketOutgoing(Timestamp timestamp, absl::string_view packet) : rtcp(timestamp, packet) {} int64_t log_time_us() const { return rtcp.timestamp.us(); } diff --git a/logging/rtc_event_log/events/rtc_event_field_encoding_parser.h b/logging/rtc_event_log/events/rtc_event_field_encoding_parser.h index c33d4bee3a..fc87faf611 100644 --- a/logging/rtc_event_log/events/rtc_event_field_encoding_parser.h +++ b/logging/rtc_event_log/events/rtc_event_field_encoding_parser.h @@ -14,6 +14,7 @@ #include #include +#include "absl/strings/string_view.h" #include "logging/rtc_event_log/events/rtc_event_field_encoding.h" // TODO(terelius): Compared to a generic 'Status' class, this @@ -29,8 +30,8 @@ class RtcEventLogParseStatus { public: static RtcEventLogParseStatus Success() { return RtcEventLogParseStatus(); } - static RtcEventLogParseStatus Error(std::string error, - std::string file, + static RtcEventLogParseStatus Error(absl::string_view error, + absl::string_view file, int line) { return RtcEventLogParseStatus(error, file, line); } @@ -44,8 +45,11 @@ class RtcEventLogParseStatus { private: RtcEventLogParseStatus() : error_() {} - RtcEventLogParseStatus(std::string error, std::string file, int line) - : error_(error + " (" + file + ": " + std::to_string(line) + ")") {} + RtcEventLogParseStatus(absl::string_view error, + absl::string_view file, + int line) + : error_(std::string(error) + " (" + std::string(file) + ": " + + std::to_string(line) + ")") {} std::string error_; }; @@ -74,15 +78,17 @@ class RtcEventLogParseStatusOr { return value_; } - static RtcEventLogParseStatusOr Error(std::string error, - std::string file, + static RtcEventLogParseStatusOr Error(absl::string_view error, + absl::string_view file, int line) { return RtcEventLogParseStatusOr(error, file, line); } private: RtcEventLogParseStatusOr() : status_() {} - RtcEventLogParseStatusOr(std::string error, std::string file, int line) + RtcEventLogParseStatusOr(absl::string_view error, + absl::string_view file, + int line) : status_(error, file, line), value_() {} RtcEventLogParseStatus status_; diff --git a/logging/rtc_event_log/events/rtc_event_field_encoding_unittest.cc b/logging/rtc_event_log/events/rtc_event_field_encoding_unittest.cc index b1554694ad..18beda1417 100644 --- a/logging/rtc_event_log/events/rtc_event_field_encoding_unittest.cc +++ b/logging/rtc_event_log/events/rtc_event_field_encoding_unittest.cc @@ -12,6 +12,7 @@ #include #include +#include "absl/strings/string_view.h" #include "api/rtc_event_log/rtc_event.h" #include "logging/rtc_event_log/encoder/var_int.h" #include "logging/rtc_event_log/events/rtc_event_field_encoding_parser.h" @@ -158,7 +159,7 @@ class RtcTestEvent final : public RtcEvent { absl::optional optional_signed32, absl::optional optional_signed64, uint32_t wrapping21, - std::string string) + absl::string_view string) : b_(b), signed32_(signed32), unsigned32_(unsigned32), @@ -255,7 +256,7 @@ class RtcEventFieldTest : public ::testing::Test { } } - void PrintBytes(const std::string& s) { + void PrintBytes(absl::string_view s) { for (auto c : s) { fprintf(stderr, "%d ", static_cast(c)); } diff --git a/logging/rtc_event_log/rtc_event_log2rtp_dump.cc b/logging/rtc_event_log/rtc_event_log2rtp_dump.cc index 93cd4652cc..a0514259aa 100644 --- a/logging/rtc_event_log/rtc_event_log2rtp_dump.cc +++ b/logging/rtc_event_log/rtc_event_log2rtp_dump.cc @@ -21,6 +21,7 @@ #include "absl/flags/parse.h" #include "absl/flags/usage.h" #include "absl/memory/memory.h" +#include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "api/array_view.h" #include "api/rtc_event_log/rtc_event_log.h" @@ -75,7 +76,7 @@ using MediaType = webrtc::ParsedRtcEventLog::MediaType; // The empty string must be validated as true, because it is the default value // of the command-line flag. In this case, no value is written to the output // variable. -absl::optional ParseSsrc(std::string str) { +absl::optional ParseSsrc(absl::string_view str) { // If the input string starts with 0x or 0X it indicates a hexadecimal number. uint32_t ssrc; auto read_mode = std::dec; @@ -84,7 +85,7 @@ absl::optional ParseSsrc(std::string str) { read_mode = std::hex; str = str.substr(2); } - std::stringstream ss(str); + std::stringstream ss(std::string{str}); ss >> read_mode >> ssrc; if (str.empty() || (!ss.fail() && ss.eof())) return ssrc; diff --git a/logging/rtc_event_log/rtc_event_log_impl.cc b/logging/rtc_event_log/rtc_event_log_impl.cc index c45352b67b..444dd48794 100644 --- a/logging/rtc_event_log/rtc_event_log_impl.cc +++ b/logging/rtc_event_log/rtc_event_log_impl.cc @@ -16,6 +16,7 @@ #include #include +#include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "api/task_queue/queued_task.h" #include "api/task_queue/task_queue_base.h" @@ -230,8 +231,8 @@ void RtcEventLogImpl::LogEventsFromMemoryToOutput() { } void RtcEventLogImpl::WriteConfigsAndHistoryToOutput( - const std::string& encoded_configs, - const std::string& encoded_history) { + absl::string_view encoded_configs, + absl::string_view encoded_history) { // This function is used to merge the strings instead of calling the output // object twice with small strings. The function also avoids copying any // strings in the typical case where there are no config events. @@ -240,7 +241,11 @@ void RtcEventLogImpl::WriteConfigsAndHistoryToOutput( } else if (encoded_history.empty()) { WriteToOutput(encoded_configs); // Very unusual case. } else { - WriteToOutput(encoded_configs + encoded_history); + std::string s; + s.reserve(encoded_configs.size() + encoded_history.size()); + s.append(encoded_configs.data(), encoded_configs.size()); + s.append(encoded_history.data(), encoded_history.size()); + WriteToOutput(s); } } @@ -257,7 +262,7 @@ void RtcEventLogImpl::StopLoggingInternal() { StopOutput(); } -void RtcEventLogImpl::WriteToOutput(const std::string& output_string) { +void RtcEventLogImpl::WriteToOutput(absl::string_view output_string) { RTC_DCHECK(event_output_ && event_output_->IsActive()); if (!event_output_->Write(output_string)) { RTC_LOG(LS_ERROR) << "Failed to write RTC event to output."; diff --git a/logging/rtc_event_log/rtc_event_log_impl.h b/logging/rtc_event_log/rtc_event_log_impl.h index 61e90d139d..6c6417254e 100644 --- a/logging/rtc_event_log/rtc_event_log_impl.h +++ b/logging/rtc_event_log/rtc_event_log_impl.h @@ -17,6 +17,7 @@ #include #include +#include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "api/rtc_event_log/rtc_event.h" #include "api/rtc_event_log/rtc_event_log.h" @@ -54,10 +55,10 @@ class RtcEventLogImpl final : public RtcEventLog { void StopOutput() RTC_RUN_ON(task_queue_); - void WriteConfigsAndHistoryToOutput(const std::string& encoded_configs, - const std::string& encoded_history) + void WriteConfigsAndHistoryToOutput(absl::string_view encoded_configs, + absl::string_view encoded_history) RTC_RUN_ON(task_queue_); - void WriteToOutput(const std::string& output_string) RTC_RUN_ON(task_queue_); + void WriteToOutput(absl::string_view output_string) RTC_RUN_ON(task_queue_); void StopLoggingInternal() RTC_RUN_ON(task_queue_); diff --git a/logging/rtc_event_log/rtc_event_log_parser.cc b/logging/rtc_event_log/rtc_event_log_parser.cc index 21a44eeb12..e0a9d99608 100644 --- a/logging/rtc_event_log/rtc_event_log_parser.cc +++ b/logging/rtc_event_log/rtc_event_log_parser.cc @@ -19,6 +19,7 @@ #include #include "absl/memory/memory.h" +#include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "api/network_state_predictor.h" #include "api/rtc_event_log/rtc_event_log.h" @@ -1114,7 +1115,7 @@ void ParsedRtcEventLog::Clear() { } ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseFile( - const std::string& filename) { + absl::string_view filename) { FileWrapper file = FileWrapper::OpenReadOnly(filename); if (!file.is_open()) { RTC_LOG(LS_WARNING) << "Could not open file " << filename @@ -1140,12 +1141,12 @@ ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseFile( } ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseString( - const std::string& s) { + absl::string_view s) { return ParseStream(s); } ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseStream( - const std::string& s) { + absl::string_view s) { Clear(); ParseStatus status = ParseStreamInternal(s); diff --git a/logging/rtc_event_log/rtc_event_log_parser.h b/logging/rtc_event_log/rtc_event_log_parser.h index 9ef4e347de..8b1cba25e3 100644 --- a/logging/rtc_event_log/rtc_event_log_parser.h +++ b/logging/rtc_event_log/rtc_event_log_parser.h @@ -18,6 +18,7 @@ #include #include "absl/base/attributes.h" +#include "absl/strings/string_view.h" #include "api/rtc_event_log/rtc_event_log.h" #include "call/video_receive_stream.h" #include "call/video_send_stream.h" @@ -379,13 +380,13 @@ class ParsedRtcEventLog { void Clear(); // Reads an RtcEventLog file and returns success if parsing was successful. - ParseStatus ParseFile(const std::string& file_name); + ParseStatus ParseFile(absl::string_view file_name); // Reads an RtcEventLog from a string and returns success if successful. - ParseStatus ParseString(const std::string& s); + ParseStatus ParseString(absl::string_view s); // Reads an RtcEventLog from an string and returns success if successful. - ParseStatus ParseStream(const std::string& s); + ParseStatus ParseStream(absl::string_view s); MediaType GetMediaType(uint32_t ssrc, PacketDirection direction) const; diff --git a/logging/rtc_event_log/rtc_event_log_unittest_helper.cc b/logging/rtc_event_log/rtc_event_log_unittest_helper.cc index b4ee9d7803..2607028f60 100644 --- a/logging/rtc_event_log/rtc_event_log_unittest_helper.cc +++ b/logging/rtc_event_log/rtc_event_log_unittest_helper.cc @@ -21,6 +21,7 @@ #include #include +#include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "api/array_view.h" #include "api/network_state_predictor.h" @@ -81,7 +82,7 @@ void ShuffleInPlace(Random* prng, rtc::ArrayView array) { } absl::optional GetExtensionId(const std::vector& extensions, - const std::string& uri) { + absl::string_view uri) { for (const auto& extension : extensions) { if (extension.uri == uri) return extension.id; diff --git a/logging/rtc_event_log/rtc_stream_config.cc b/logging/rtc_event_log/rtc_stream_config.cc index d4d30d00bc..aa107c80bc 100644 --- a/logging/rtc_event_log/rtc_stream_config.cc +++ b/logging/rtc_event_log/rtc_stream_config.cc @@ -10,6 +10,8 @@ #include "logging/rtc_event_log/rtc_stream_config.h" +#include "absl/strings/string_view.h" + namespace webrtc { namespace rtclog { @@ -30,7 +32,7 @@ bool StreamConfig::operator!=(const StreamConfig& other) const { return !(*this == other); } -StreamConfig::Codec::Codec(const std::string& payload_name, +StreamConfig::Codec::Codec(absl::string_view payload_name, int payload_type, int rtx_payload_type) : payload_name(payload_name), diff --git a/logging/rtc_event_log/rtc_stream_config.h b/logging/rtc_event_log/rtc_stream_config.h index a81249aebf..d114332d34 100644 --- a/logging/rtc_event_log/rtc_stream_config.h +++ b/logging/rtc_event_log/rtc_stream_config.h @@ -16,6 +16,7 @@ #include #include +#include "absl/strings/string_view.h" #include "api/rtp_headers.h" #include "api/rtp_parameters.h" @@ -41,7 +42,7 @@ struct StreamConfig { RtcpMode rtcp_mode = RtcpMode::kReducedSize; struct Codec { - Codec(const std::string& payload_name, + Codec(absl::string_view payload_name, int payload_type, int rtx_payload_type); diff --git a/test/logging/BUILD.gn b/test/logging/BUILD.gn index 1af2ecfdac..301c0e59c0 100644 --- a/test/logging/BUILD.gn +++ b/test/logging/BUILD.gn @@ -28,5 +28,8 @@ rtc_library("log_writer") { "../../rtc_base:stringutils", "../../test:fileutils", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] + absl_deps = [ + "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/types:optional", + ] } diff --git a/test/logging/file_log_writer.cc b/test/logging/file_log_writer.cc index 9598bc079c..9189e1630d 100644 --- a/test/logging/file_log_writer.cc +++ b/test/logging/file_log_writer.cc @@ -11,6 +11,7 @@ #include +#include "absl/strings/string_view.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" #include "test/testsupport/file_utils.h" @@ -18,8 +19,8 @@ namespace webrtc { namespace webrtc_impl { -FileLogWriter::FileLogWriter(std::string file_path) - : out_(std::fopen(file_path.c_str(), "wb")) { +FileLogWriter::FileLogWriter(absl::string_view file_path) + : out_(std::fopen(std::string(file_path).c_str(), "wb")) { RTC_CHECK(out_ != nullptr) << "Failed to open file: '" << file_path << "' for writing."; } @@ -46,7 +47,7 @@ void FileLogWriter::Flush() { } // namespace webrtc_impl -FileLogWriterFactory::FileLogWriterFactory(std::string base_path) +FileLogWriterFactory::FileLogWriterFactory(absl::string_view base_path) : base_path_(base_path) { for (size_t i = 0; i < base_path.size(); ++i) { if (base_path[i] == '/') @@ -57,7 +58,8 @@ FileLogWriterFactory::FileLogWriterFactory(std::string base_path) FileLogWriterFactory::~FileLogWriterFactory() {} std::unique_ptr FileLogWriterFactory::Create( - std::string filename) { - return std::make_unique(base_path_ + filename); + absl::string_view filename) { + return std::make_unique(base_path_ + + std::string(filename)); } } // namespace webrtc diff --git a/test/logging/file_log_writer.h b/test/logging/file_log_writer.h index b1355d325a..c49b96ceff 100644 --- a/test/logging/file_log_writer.h +++ b/test/logging/file_log_writer.h @@ -15,13 +15,14 @@ #include #include +#include "absl/strings/string_view.h" #include "test/logging/log_writer.h" namespace webrtc { namespace webrtc_impl { class FileLogWriter final : public RtcEventLogOutput { public: - explicit FileLogWriter(std::string file_path); + explicit FileLogWriter(absl::string_view file_path); ~FileLogWriter() final; bool IsActive() const override; bool Write(absl::string_view value) override; @@ -33,10 +34,11 @@ class FileLogWriter final : public RtcEventLogOutput { } // namespace webrtc_impl class FileLogWriterFactory final : public LogWriterFactoryInterface { public: - explicit FileLogWriterFactory(std::string base_path); + explicit FileLogWriterFactory(absl::string_view base_path); ~FileLogWriterFactory() final; - std::unique_ptr Create(std::string filename) override; + std::unique_ptr Create( + absl::string_view filename) override; private: const std::string base_path_; diff --git a/test/logging/log_writer.cc b/test/logging/log_writer.cc index a20d026edc..d9b8c1e68f 100644 --- a/test/logging/log_writer.cc +++ b/test/logging/log_writer.cc @@ -9,16 +9,18 @@ */ #include "test/logging/log_writer.h" +#include "absl/strings/string_view.h" + namespace webrtc { LogWriterFactoryAddPrefix::LogWriterFactoryAddPrefix( LogWriterFactoryInterface* base, - std::string prefix) + absl::string_view prefix) : base_factory_(base), prefix_(prefix) {} std::unique_ptr LogWriterFactoryAddPrefix::Create( - std::string filename) { - return base_factory_->Create(prefix_ + filename); + absl::string_view filename) { + return base_factory_->Create(prefix_ + std::string(filename)); } } // namespace webrtc diff --git a/test/logging/log_writer.h b/test/logging/log_writer.h index 00981526f0..335dab353f 100644 --- a/test/logging/log_writer.h +++ b/test/logging/log_writer.h @@ -16,6 +16,7 @@ #include #include +#include "absl/strings/string_view.h" #include "api/rtc_event_log_output.h" #include "rtc_base/strings/string_builder.h" @@ -42,15 +43,17 @@ inline void LogWriteFormat(RtcEventLogOutput* out_, const char* fmt, ...) { class LogWriterFactoryInterface { public: - virtual std::unique_ptr Create(std::string filename) = 0; + virtual std::unique_ptr Create( + absl::string_view filename) = 0; virtual ~LogWriterFactoryInterface() = default; }; class LogWriterFactoryAddPrefix : public LogWriterFactoryInterface { public: LogWriterFactoryAddPrefix(LogWriterFactoryInterface* base, - std::string prefix); - std::unique_ptr Create(std::string filename) override; + absl::string_view prefix); + std::unique_ptr Create( + absl::string_view filename) override; private: LogWriterFactoryInterface* const base_factory_; diff --git a/test/logging/memory_log_writer.cc b/test/logging/memory_log_writer.cc index 9c5f32fe13..eae9223c77 100644 --- a/test/logging/memory_log_writer.cc +++ b/test/logging/memory_log_writer.cc @@ -11,6 +11,7 @@ #include +#include "absl/strings/string_view.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" @@ -19,7 +20,7 @@ namespace { class MemoryLogWriter final : public RtcEventLogOutput { public: explicit MemoryLogWriter(std::map* target, - std::string filename) + absl::string_view filename) : target_(target), filename_(filename) {} ~MemoryLogWriter() final { target_->insert({filename_, std::move(buffer_)}); } bool IsActive() const override { return true; } @@ -40,7 +41,8 @@ class MemoryLogWriterFactory final : public LogWriterFactoryInterface { explicit MemoryLogWriterFactory(std::map* target) : target_(target) {} ~MemoryLogWriterFactory() override {} - std::unique_ptr Create(std::string filename) override { + std::unique_ptr Create( + absl::string_view filename) override { return std::make_unique(target_, filename); }