Remove all remaining non-test uses of std::stringstream.

Bug: webrtc:8982
Change-Id: I635a8545c46dc8c89663d64af351e22e65cbcb33
Reviewed-on: https://webrtc-review.googlesource.com/98880
Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24715}
diff --git a/api/rtcerror.cc b/api/rtcerror.cc
index 55ac15e..039e7f3 100644
--- a/api/rtcerror.cc
+++ b/api/rtcerror.cc
@@ -36,32 +36,8 @@
 
 namespace webrtc {
 
-RTCError::RTCError(RTCError&& other)
-    : type_(other.type_), have_string_message_(other.have_string_message_) {
-  if (have_string_message_) {
-    new (&string_message_) std::string(std::move(other.string_message_));
-  } else {
-    static_message_ = other.static_message_;
-  }
-}
-
-RTCError& RTCError::operator=(RTCError&& other) {
-  type_ = other.type_;
-  if (other.have_string_message_) {
-    set_message(std::move(other.string_message_));
-  } else {
-    set_message(other.static_message_);
-  }
-  return *this;
-}
-
-RTCError::~RTCError() {
-  // If we hold a message string that was built, rather than a static string,
-  // we need to delete it.
-  if (have_string_message_) {
-    string_message_.~basic_string();
-  }
-}
+RTCError::RTCError(RTCError&& other) = default;
+RTCError& RTCError::operator=(RTCError&& other) = default;
 
 // static
 RTCError RTCError::OK() {
@@ -69,28 +45,11 @@
 }
 
 const char* RTCError::message() const {
-  if (have_string_message_) {
-    return string_message_.c_str();
-  } else {
-    return static_message_;
-  }
+  return message_.c_str();
 }
 
-void RTCError::set_message(const char* message) {
-  if (have_string_message_) {
-    string_message_.~basic_string();
-    have_string_message_ = false;
-  }
-  static_message_ = message;
-}
-
-void RTCError::set_message(std::string&& message) {
-  if (!have_string_message_) {
-    new (&string_message_) std::string(std::move(message));
-    have_string_message_ = true;
-  } else {
-    string_message_ = message;
-  }
+void RTCError::set_message(std::string message) {
+  message_ = std::move(message);
 }
 
 // TODO(jonasolsson): Change to use absl::string_view when it's available.
diff --git a/api/rtcerror.h b/api/rtcerror.h
index c87ce91..4910682 100644
--- a/api/rtcerror.h
+++ b/api/rtcerror.h
@@ -86,12 +86,9 @@
   // Creates a "no error" error.
   RTCError() {}
   explicit RTCError(RTCErrorType type) : type_(type) {}
-  // For performance, prefer using the constructor that takes a const char* if
-  // the message is a static string.
-  RTCError(RTCErrorType type, const char* message)
-      : type_(type), static_message_(message), have_string_message_(false) {}
-  RTCError(RTCErrorType type, std::string&& message)
-      : type_(type), string_message_(message), have_string_message_(true) {}
+
+  RTCError(RTCErrorType type, std::string message)
+      : type_(type), message_(std::move(message)) {}
 
   // Delete the copy constructor and assignment operator; there aren't any use
   // cases where you should need to copy an RTCError, as opposed to moving it.
@@ -103,8 +100,6 @@
   RTCError(RTCError&& other);
   RTCError& operator=(RTCError&& other);
 
-  ~RTCError();
-
   // Identical to default constructed error.
   //
   // Preferred over the default constructor for code readability.
@@ -118,10 +113,8 @@
   // anything but logging/diagnostics, since messages are not guaranteed to be
   // stable.
   const char* message() const;
-  // For performance, prefer using the method that takes a const char* if the
-  // message is a static string.
-  void set_message(const char* message);
-  void set_message(std::string&& message);
+
+  void set_message(std::string message);
 
   // Convenience method for situations where you only care whether or not an
   // error occurred.
@@ -129,16 +122,7 @@
 
  private:
   RTCErrorType type_ = RTCErrorType::NONE;
-  // For performance, we use static strings wherever possible. But in some
-  // cases the error string may need to be constructed, in which case an
-  // std::string is used.
-  union {
-    const char* static_message_ = "";
-    std::string string_message_;
-  };
-  // Whether or not |static_message_| or |string_message_| is being used in the
-  // above union.
-  bool have_string_message_ = false;
+  std::string message_;
 };
 
 // Outputs the error as a friendly string. Update this method when adding a new
diff --git a/api/rtcerror_unittest.cc b/api/rtcerror_unittest.cc
index 90593cf..a1ea83f 100644
--- a/api/rtcerror_unittest.cc
+++ b/api/rtcerror_unittest.cc
@@ -222,7 +222,8 @@
 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
 
 TEST(RTCErrorOrDeathTest, ConstructWithOkError) {
-  EXPECT_DEATH(RTCErrorOr<int> err = RTCError::OK(), "");
+  RTCErrorOr<int> err;
+  EXPECT_DEATH(err = RTCError::OK(), "");
 }
 
 TEST(RTCErrorOrDeathTest, DereferenceErrorValue) {
diff --git a/api/units/time_delta.h b/api/units/time_delta.h
index 6e69333..ec36417 100644
--- a/api/units/time_delta.h
+++ b/api/units/time_delta.h
@@ -17,6 +17,7 @@
 
 #include <stdint.h>
 #include <cmath>
+#include <cstdlib>
 #include <limits>
 #include <string>