From fb59a6aa3f718241506fb644f4daa295f992d596 Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Fri, 20 Sep 2019 09:33:02 +0200 Subject: [PATCH] Return `const char*` from ToString(RTCErrorType error). Returning absl::string_view causes problems to the Chromium/WebRTC component build because absl::operator<< needs to be exported. This CL switches to `const char*` which should be enough to avoid to generate temporaries. Bug: webrtc:9419 Change-Id: If169a6f95c7efd21ac8ce108c7f2f80a76ff2313 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153842 Reviewed-by: Karl Wiberg Commit-Queue: Mirko Bonadei Cr-Commit-Position: refs/heads/master@{#29250} --- api/BUILD.gn | 1 - api/rtc_error.cc | 5 ++--- api/rtc_error.h | 5 ++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/api/BUILD.gn b/api/BUILD.gn index f6be2c2b36..8366025197 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -227,7 +227,6 @@ rtc_source_set("rtc_error") { "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base/system:rtc_export", - "//third_party/abseil-cpp/absl/strings", ] } diff --git a/api/rtc_error.cc b/api/rtc_error.cc index 51fd07f699..c9ad7cb634 100644 --- a/api/rtc_error.cc +++ b/api/rtc_error.cc @@ -10,12 +10,11 @@ #include "api/rtc_error.h" -#include "absl/strings/string_view.h" #include "rtc_base/arraysize.h" namespace { -const absl::string_view kRTCErrorTypeNames[] = { +const char* kRTCErrorTypeNames[] = { "NONE", "UNSUPPORTED_OPERATION", "UNSUPPORTED_PARAMETER", @@ -53,7 +52,7 @@ void RTCError::set_message(std::string message) { message_ = std::move(message); } -absl::string_view ToString(RTCErrorType error) { +const char* ToString(RTCErrorType error) { int index = static_cast(error); return kRTCErrorTypeNames[index]; } diff --git a/api/rtc_error.h b/api/rtc_error.h index fdc1999299..ffdcc0a258 100644 --- a/api/rtc_error.h +++ b/api/rtc_error.h @@ -17,7 +17,6 @@ #include #include // For std::move. -#include "absl/strings/string_view.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" #include "rtc_base/system/rtc_export.h" @@ -130,9 +129,9 @@ class RTC_EXPORT RTCError { // Outputs the error as a friendly string. Update this method when adding a new // error type. // -// Only intended to be used for logging/diagnostics. The string_view points +// Only intended to be used for logging/diagnostics. The returned char* points // to literal string that lives for the whole duration of the program. -absl::string_view ToString(RTCErrorType error); +const char* ToString(RTCErrorType error); #ifdef UNIT_TEST inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)