Bug 1589285 part 2. Add Span<const char> overloads of some XPCOM string methods. r=kmag
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 17 Oct 2019 22:09:46 +0000
changeset 498649 8349fe6d5612cd2efb5d0815f8cca6ee857e523d
parent 498648 73ade09e6739f63baff12bbee403be4e74ce1d73
child 498650 fbd7b66b2d88fd3e403d4b50eeed9753a61715fc
push id98578
push userbzbarsky@mozilla.com
push dateTue, 22 Oct 2019 22:17:59 +0000
treeherderautoland@fbd7b66b2d88 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1589285
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1589285 part 2. Add Span<const char> overloads of some XPCOM string methods. r=kmag Differential Revision: https://phabricator.services.mozilla.com/D49532
xpcom/string/nsString.h
xpcom/string/nsTDependentSubstring.h
xpcom/string/nsTString.h
xpcom/string/nsTSubstring.h
--- a/xpcom/string/nsString.h
+++ b/xpcom/string/nsString.h
@@ -72,16 +72,20 @@ class NS_ConvertASCIItoUTF16 : public ns
   NS_ConvertASCIItoUTF16(const char* aCString, uint32_t aLength) {
     AppendASCIItoUTF16(Substring(aCString, aLength), *this);
   }
 
   explicit NS_ConvertASCIItoUTF16(const nsACString& aCString) {
     AppendASCIItoUTF16(aCString, *this);
   }
 
+  explicit NS_ConvertASCIItoUTF16(mozilla::Span<const char> aCString) {
+    AppendASCIItoUTF16(aCString, *this);
+  }
+
  private:
   // NOT TO BE IMPLEMENTED
   NS_ConvertASCIItoUTF16(char16_t) = delete;
 };
 
 /**
  * A helper class that converts a UTF-16 string to UTF-8
  */
--- a/xpcom/string/nsTDependentSubstring.h
+++ b/xpcom/string/nsTDependentSubstring.h
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 // IWYU pragma: private, include "nsString.h"
 
 #ifndef nsTDependentSubstring_h
 #define nsTDependentSubstring_h
 
 #include "nsTSubstring.h"
 #include "nsTLiteralString.h"
+#include "mozilla/Span.h"
 
 /**
  * nsTDependentSubstring_CharT
  *
  * A string class which wraps an external array of string characters. It
  * is the client code's responsibility to ensure that the external buffer
  * remains valid for a long as the string is alive.
  *
@@ -63,16 +64,19 @@ class nsTDependentSubstring : public nsT
       : substring_type() {
     Rebind(aStr, aStartPos, aLength);
   }
 
   nsTDependentSubstring(const char_type* aData, size_type aLength)
       : substring_type(const_cast<char_type*>(aData), aLength, DataFlags(0),
                        ClassFlags(0)) {}
 
+  explicit nsTDependentSubstring(mozilla::Span<const char_type> aData)
+      : nsTDependentSubstring(aData.Elements(), aData.Length()) {}
+
   nsTDependentSubstring(const char_type* aStart, const char_type* aEnd);
 
 #if defined(MOZ_USE_CHAR16_WRAPPER)
   template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>>
   nsTDependentSubstring(char16ptr_t aData, size_type aLength)
       : nsTDependentSubstring(static_cast<const char16_t*>(aData), aLength) {}
 
   template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>>
--- a/xpcom/string/nsTString.h
+++ b/xpcom/string/nsTString.h
@@ -66,16 +66,19 @@ class nsTString : public nsTSubstring<T>
 
   nsTString() : substring_type(ClassFlags::NULL_TERMINATED) {}
 
   explicit nsTString(const char_type* aData, size_type aLength = size_type(-1))
       : substring_type(ClassFlags::NULL_TERMINATED) {
     this->Assign(aData, aLength);
   }
 
+  explicit nsTString(mozilla::Span<const char_type> aData)
+      : nsTString(aData.Elements(), aData.Length()) {}
+
 #if defined(MOZ_USE_CHAR16_WRAPPER)
   template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>>
   explicit nsTString(char16ptr_t aStr, size_type aLength = size_type(-1))
       : substring_type(ClassFlags::NULL_TERMINATED) {
     this->Assign(static_cast<const char16_t*>(aStr), aLength);
   }
 #endif
 
--- a/xpcom/string/nsTSubstring.h
+++ b/xpcom/string/nsTSubstring.h
@@ -963,16 +963,28 @@ class nsTSubstring : public mozilla::det
                            const fallible_t& aFallible) {
     auto len = aSpan.Length();
     if (len > mozilla::MaxValue<size_type>::value) {
       return false;
     }
     return Append(aSpan.Elements(), len, aFallible);
   }
 
+  void NS_FASTCALL AssignASCII(mozilla::Span<const char> aData) {
+    AssignASCII(aData.Elements(), aData.Length());
+  }
+  MOZ_MUST_USE bool NS_FASTCALL AssignASCII(mozilla::Span<const char> aData,
+                                            const fallible_t& aFallible) {
+    return AssignASCII(aData.Elements(), aData.Length(), aFallible);
+  }
+
+  void AppendASCII(mozilla::Span<const char> aData) {
+    AppendASCII(aData.Elements(), aData.Length());
+  }
+
   template <typename Q = T, typename EnableIfChar = mozilla::CharOnlyT<Q>>
   operator mozilla::Span<uint8_t>() {
     return mozilla::MakeSpan(reinterpret_cast<uint8_t*>(BeginWriting()),
                              base_string_type::Length());
   }
 
   template <typename Q = T, typename EnableIfChar = mozilla::CharOnlyT<Q>>
   operator mozilla::Span<const uint8_t>() const {