Switch QuicheMemSlice to a platform-independent implementation.

Protected by FLAGS_quic_restart_flag_quiche_use_default_memslice.

PiperOrigin-RevId: 703577230
diff --git a/build/source_list.bzl b/build/source_list.bzl
index 5181580..2294c69 100644
--- a/build/source_list.bzl
+++ b/build/source_list.bzl
@@ -43,6 +43,7 @@
     "common/quiche_crypto_logging.h",
     "common/quiche_data_reader.h",
     "common/quiche_data_writer.h",
+    "common/quiche_default_mem_slice_impl.h",
     "common/quiche_endian.h",
     "common/quiche_feature_flags_list.h",
     "common/quiche_intrusive_list.h",
diff --git a/build/source_list.gni b/build/source_list.gni
index 66e3094..87e9862 100644
--- a/build/source_list.gni
+++ b/build/source_list.gni
@@ -43,6 +43,7 @@
     "src/quiche/common/quiche_crypto_logging.h",
     "src/quiche/common/quiche_data_reader.h",
     "src/quiche/common/quiche_data_writer.h",
+    "src/quiche/common/quiche_default_mem_slice_impl.h",
     "src/quiche/common/quiche_endian.h",
     "src/quiche/common/quiche_feature_flags_list.h",
     "src/quiche/common/quiche_intrusive_list.h",
diff --git a/build/source_list.json b/build/source_list.json
index 05e7585..3b28c42 100644
--- a/build/source_list.json
+++ b/build/source_list.json
@@ -42,6 +42,7 @@
     "quiche/common/quiche_crypto_logging.h",
     "quiche/common/quiche_data_reader.h",
     "quiche/common/quiche_data_writer.h",
+    "quiche/common/quiche_default_mem_slice_impl.h",
     "quiche/common/quiche_endian.h",
     "quiche/common/quiche_feature_flags_list.h",
     "quiche/common/quiche_intrusive_list.h",
diff --git a/quiche/common/platform/default/quiche_platform_impl/quiche_mem_slice_impl.h b/quiche/common/platform/default/quiche_platform_impl/quiche_mem_slice_impl.h
index bf78b29..ed4c326 100644
--- a/quiche/common/platform/default/quiche_platform_impl/quiche_mem_slice_impl.h
+++ b/quiche/common/platform/default/quiche_platform_impl/quiche_mem_slice_impl.h
@@ -1,86 +1,11 @@
 #ifndef QUICHE_COMMON_PLATFORM_DEFAULT_QUICHE_PLATFORM_IMPL_QUICHE_MEM_SLICE_IMPL_H_
 #define QUICHE_COMMON_PLATFORM_DEFAULT_QUICHE_PLATFORM_IMPL_QUICHE_MEM_SLICE_IMPL_H_
 
-#include <cstddef>
-#include <cstdlib>
-#include <memory>
-#include <utility>
-
-#include "quiche/common/platform/api/quiche_export.h"
-#include "quiche/common/quiche_buffer_allocator.h"
-#include "quiche/common/quiche_callbacks.h"
+#include "quiche/common/quiche_default_mem_slice_impl.h"
 
 namespace quiche {
 
-class QUICHE_EXPORT QuicheMemSliceImpl {
- public:
-  QuicheMemSliceImpl() = default;
-
-  explicit QuicheMemSliceImpl(QuicheBuffer buffer)
-      : data_(buffer.data()), size_(buffer.size()) {
-    QuicheUniqueBufferPtr owned = buffer.Release();
-    QuicheBufferAllocator* allocator = owned.get_deleter().allocator();
-    owned.release();
-    done_callback_ = [allocator](const char* ptr) {
-      allocator->Delete(const_cast<char*>(ptr));
-    };
-  }
-
-  QuicheMemSliceImpl(std::unique_ptr<char[]> buffer, size_t length)
-      : data_(buffer.release()),
-        size_(length),
-        done_callback_(+[](const char* ptr) { delete[] ptr; }) {}
-
-  QuicheMemSliceImpl(const char* buffer, size_t length,
-                     SingleUseCallback<void(const char*)> done_callback)
-      : data_(buffer),
-        size_(length),
-        done_callback_(std::move(done_callback)) {}
-
-  QuicheMemSliceImpl(const QuicheMemSliceImpl& other) = delete;
-  QuicheMemSliceImpl& operator=(const QuicheMemSliceImpl& other) = delete;
-
-  // Move constructors. |other| will not hold a reference to the data buffer
-  // after this call completes.
-  QuicheMemSliceImpl(QuicheMemSliceImpl&& other) {
-    data_ = other.data_;
-    size_ = other.size_;
-    done_callback_ = std::move(other.done_callback_);
-    other.data_ = nullptr;
-    other.size_ = 0;
-    other.done_callback_ = nullptr;
-  }
-  QuicheMemSliceImpl& operator=(QuicheMemSliceImpl&& other) {
-    Reset();
-    data_ = other.data_;
-    size_ = other.size_;
-    done_callback_ = std::move(other.done_callback_);
-    other.data_ = nullptr;
-    other.size_ = 0;
-    other.done_callback_ = nullptr;
-    return *this;
-  }
-
-  ~QuicheMemSliceImpl() { Reset(); }
-
-  void Reset() {
-    if (done_callback_ && data_ != nullptr) {
-      std::move(done_callback_)(data_);
-    }
-    data_ = nullptr;
-    size_ = 0;
-    done_callback_ = nullptr;
-  }
-
-  const char* data() const { return data_; }
-  size_t length() const { return size_; }
-  bool empty() const { return size_ == 0; }
-
- private:
-  const char* data_ = nullptr;
-  size_t size_ = 0;
-  SingleUseCallback<void(const char*)> done_callback_ = nullptr;
-};
+using QuicheMemSliceImpl = QuicheDefaultMemSliceImpl;
 
 }  // namespace quiche
 
diff --git a/quiche/common/quiche_default_mem_slice_impl.h b/quiche/common/quiche_default_mem_slice_impl.h
new file mode 100644
index 0000000..e2acde0
--- /dev/null
+++ b/quiche/common/quiche_default_mem_slice_impl.h
@@ -0,0 +1,89 @@
+#ifndef QUICHE_COMMON_QUICHE_DEFAULT_MEM_SLICE_IMPL_H_
+#define QUICHE_COMMON_QUICHE_DEFAULT_MEM_SLICE_IMPL_H_
+
+#include <cstddef>
+#include <cstdlib>
+#include <memory>
+#include <utility>
+
+#include "quiche/common/platform/api/quiche_export.h"
+#include "quiche/common/quiche_buffer_allocator.h"
+#include "quiche/common/quiche_callbacks.h"
+
+namespace quiche {
+
+// The default (and soon, hopefully the only) implementation of QuicheMemSlice.
+class QUICHE_EXPORT QuicheDefaultMemSliceImpl {
+ public:
+  QuicheDefaultMemSliceImpl() = default;
+
+  explicit QuicheDefaultMemSliceImpl(QuicheBuffer buffer)
+      : data_(buffer.data()), size_(buffer.size()) {
+    QuicheUniqueBufferPtr owned = buffer.Release();
+    QuicheBufferAllocator* allocator = owned.get_deleter().allocator();
+    owned.release();
+    done_callback_ = [allocator](const char* ptr) {
+      allocator->Delete(const_cast<char*>(ptr));
+    };
+  }
+
+  QuicheDefaultMemSliceImpl(std::unique_ptr<char[]> buffer, size_t length)
+      : data_(buffer.release()),
+        size_(length),
+        done_callback_(+[](const char* ptr) { delete[] ptr; }) {}
+
+  QuicheDefaultMemSliceImpl(const char* buffer, size_t length,
+                            SingleUseCallback<void(const char*)> done_callback)
+      : data_(buffer),
+        size_(length),
+        done_callback_(std::move(done_callback)) {}
+
+  QuicheDefaultMemSliceImpl(const QuicheDefaultMemSliceImpl& other) = delete;
+  QuicheDefaultMemSliceImpl& operator=(const QuicheDefaultMemSliceImpl& other) =
+      delete;
+
+  // Move constructors. |other| will not hold a reference to the data buffer
+  // after this call completes.
+  QuicheDefaultMemSliceImpl(QuicheDefaultMemSliceImpl&& other) {
+    data_ = other.data_;
+    size_ = other.size_;
+    done_callback_ = std::move(other.done_callback_);
+    other.data_ = nullptr;
+    other.size_ = 0;
+    other.done_callback_ = nullptr;
+  }
+  QuicheDefaultMemSliceImpl& operator=(QuicheDefaultMemSliceImpl&& other) {
+    Reset();
+    data_ = other.data_;
+    size_ = other.size_;
+    done_callback_ = std::move(other.done_callback_);
+    other.data_ = nullptr;
+    other.size_ = 0;
+    other.done_callback_ = nullptr;
+    return *this;
+  }
+
+  ~QuicheDefaultMemSliceImpl() { Reset(); }
+
+  void Reset() {
+    if (done_callback_ && data_ != nullptr) {
+      std::move(done_callback_)(data_);
+    }
+    data_ = nullptr;
+    size_ = 0;
+    done_callback_ = nullptr;
+  }
+
+  const char* data() const { return data_; }
+  size_t length() const { return size_; }
+  bool empty() const { return size_ == 0; }
+
+ private:
+  const char* data_ = nullptr;
+  size_t size_ = 0;
+  SingleUseCallback<void(const char*)> done_callback_ = nullptr;
+};
+
+}  // namespace quiche
+
+#endif  // QUICHE_COMMON_QUICHE_DEFAULT_MEM_SLICE_IMPL_H_