Bug 1377351 - Part 3: Expose nsA[C]String::Assign(nsA[C]String&&) overload as take_from to rust, r=froydnj
authorNika Layzell <nika@thelayzells.com>
Mon, 02 Oct 2017 10:58:18 -0400
changeset 387002 2f081c8282658b9977e595be588ab2eb5523b012
parent 387001 4b8f494ccca34f595e929b0808eea935d81b1368
child 387003 1aa544eccfc2546cdf5a321c912c5619468c587a
push id32705
push userryanvm@gmail.com
push dateThu, 19 Oct 2017 01:01:49 +0000
treeherdermozilla-central@a21099ce055f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1377351
milestone58.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 1377351 - Part 3: Expose nsA[C]String::Assign(nsA[C]String&&) overload as take_from to rust, r=froydnj MozReview-Commit-ID: 4YNPi3iRo78
xpcom/rust/nsstring/src/lib.rs
xpcom/string/nsSubstring.cpp
--- a/xpcom/rust/nsstring/src/lib.rs
+++ b/xpcom/rust/nsstring/src/lib.rs
@@ -174,16 +174,17 @@ macro_rules! define_string_types {
 
         StringLike = $StringLike: ident;
         StringAdapter = $StringAdapter: ident;
 
         StringRepr = $StringRepr: ident;
 
         drop = $drop: ident;
         assign = $assign: ident, $fallible_assign: ident;
+        take_from = $take_from: ident, $fallible_take_from: ident;
         append = $append: ident, $fallible_append: ident;
         set_length = $set_length: ident, $fallible_set_length: ident;
         begin_writing = $begin_writing: ident, $fallible_begin_writing: ident;
     } => {
         /// The representation of a ns[C]String type in C++. This type is
         /// used internally by our definition of ns[C]String to ensure layout
         /// compatibility with the C++ ns[C]String type.
         ///
@@ -265,16 +266,35 @@ macro_rules! define_string_types {
             pub fn fallible_assign<T: $StringLike + ?Sized>(&mut self, other: &T) -> Result<(), ()> {
                 if unsafe { $fallible_assign(self, other.adapt().as_ptr()) } {
                     Ok(())
                 } else {
                     Err(())
                 }
             }
 
+            /// Take the value of `other` and set `self`, overwriting any value
+            /// currently stored. The passed-in string will be truncated.
+            pub fn take_from(&mut self, other: &mut $AString) {
+                unsafe { $take_from(self, other) };
+            }
+
+            /// Take the value of `other` and set `self`, overwriting any value
+            /// currently stored. If this function fails, the source string will
+            /// be left untouched, otherwise it will be truncated.
+            ///
+            /// Returns Ok(()) on success, and Err(()) if the allocation failed.
+            pub fn fallible_take_from(&mut self, other: &mut $AString) -> Result<(), ()> {
+                if unsafe { $fallible_take_from(self, other) } {
+                    Ok(())
+                } else {
+                    Err(())
+                }
+            }
+
             /// Append the value of `other` into self.
             pub fn append<T: $StringLike + ?Sized>(&mut self, other: &T) {
                 unsafe { $append(self, other.adapt().as_ptr()) };
             }
 
             /// Append the value of `other` into self.
             ///
             /// Returns Ok(()) on success, and Err(()) if the allocation failed.
@@ -771,16 +791,17 @@ define_string_types! {
 
     StringLike = nsCStringLike;
     StringAdapter = nsCStringAdapter;
 
     StringRepr = nsCStringRepr;
 
     drop = Gecko_FinalizeCString;
     assign = Gecko_AssignCString, Gecko_FallibleAssignCString;
+    take_from = Gecko_TakeFromCString, Gecko_FallibleTakeFromCString;
     append = Gecko_AppendCString, Gecko_FallibleAppendCString;
     set_length = Gecko_SetLengthCString, Gecko_FallibleSetLengthCString;
     begin_writing = Gecko_BeginWritingCString, Gecko_FallibleBeginWritingCString;
 }
 
 impl nsACString {
     pub fn assign_utf16<T: nsStringLike + ?Sized>(&mut self, other: &T) {
         self.truncate();
@@ -904,16 +925,17 @@ define_string_types! {
 
     StringLike = nsStringLike;
     StringAdapter = nsStringAdapter;
 
     StringRepr = nsStringRepr;
 
     drop = Gecko_FinalizeString;
     assign = Gecko_AssignString, Gecko_FallibleAssignString;
+    take_from = Gecko_TakeFromString, Gecko_FallibleTakeFromString;
     append = Gecko_AppendString, Gecko_FallibleAppendString;
     set_length = Gecko_SetLengthString, Gecko_FallibleSetLengthString;
     begin_writing = Gecko_BeginWritingString, Gecko_FallibleBeginWritingString;
 }
 
 impl nsAString {
     pub fn assign_utf8<T: nsCStringLike + ?Sized>(&mut self, other: &T) {
         self.truncate();
@@ -989,31 +1011,35 @@ unsafe fn Gecko_IncrementStringAdoptCoun
 extern "C" {
     #[cfg(debug_assertions)]
     fn Gecko_IncrementStringAdoptCount(data: *mut c_void);
 
     // Gecko implementation in nsSubstring.cpp
     fn Gecko_FinalizeCString(this: *mut nsACString);
 
     fn Gecko_AssignCString(this: *mut nsACString, other: *const nsACString);
+    fn Gecko_TakeFromCString(this: *mut nsACString, other: *mut nsACString);
     fn Gecko_AppendCString(this: *mut nsACString, other: *const nsACString);
     fn Gecko_SetLengthCString(this: *mut nsACString, length: u32);
     fn Gecko_BeginWritingCString(this: *mut nsACString) -> *mut u8;
     fn Gecko_FallibleAssignCString(this: *mut nsACString, other: *const nsACString) -> bool;
+    fn Gecko_FallibleTakeFromCString(this: *mut nsACString, other: *mut nsACString) -> bool;
     fn Gecko_FallibleAppendCString(this: *mut nsACString, other: *const nsACString) -> bool;
     fn Gecko_FallibleSetLengthCString(this: *mut nsACString, length: u32) -> bool;
     fn Gecko_FallibleBeginWritingCString(this: *mut nsACString) -> *mut u8;
 
     fn Gecko_FinalizeString(this: *mut nsAString);
 
     fn Gecko_AssignString(this: *mut nsAString, other: *const nsAString);
+    fn Gecko_TakeFromString(this: *mut nsAString, other: *mut nsAString);
     fn Gecko_AppendString(this: *mut nsAString, other: *const nsAString);
     fn Gecko_SetLengthString(this: *mut nsAString, length: u32);
     fn Gecko_BeginWritingString(this: *mut nsAString) -> *mut u16;
     fn Gecko_FallibleAssignString(this: *mut nsAString, other: *const nsAString) -> bool;
+    fn Gecko_FallibleTakeFromString(this: *mut nsAString, other: *mut nsAString) -> bool;
     fn Gecko_FallibleAppendString(this: *mut nsAString, other: *const nsAString) -> bool;
     fn Gecko_FallibleSetLengthString(this: *mut nsAString, length: u32) -> bool;
     fn Gecko_FallibleBeginWritingString(this: *mut nsAString) -> *mut u16;
 
     // Gecko implementation in nsReadableUtils.cpp
     fn Gecko_AppendUTF16toCString(this: *mut nsACString, other: *const nsAString);
     fn Gecko_AppendUTF8toString(this: *mut nsAString, other: *const nsACString);
     fn Gecko_FallibleAppendUTF16toCString(this: *mut nsACString, other: *const nsAString) -> bool;
--- a/xpcom/string/nsSubstring.cpp
+++ b/xpcom/string/nsSubstring.cpp
@@ -375,31 +375,41 @@ void Gecko_FinalizeCString(nsACString* a
   aThis->~nsACString();
 }
 
 void Gecko_AssignCString(nsACString* aThis, const nsACString* aOther)
 {
   aThis->Assign(*aOther);
 }
 
+void Gecko_TakeFromCString(nsACString* aThis, nsACString* aOther)
+{
+  aThis->Assign(mozilla::Move(*aOther));
+}
+
 void Gecko_AppendCString(nsACString* aThis, const nsACString* aOther)
 {
   aThis->Append(*aOther);
 }
 
 void Gecko_SetLengthCString(nsACString* aThis, uint32_t aLength)
 {
   aThis->SetLength(aLength);
 }
 
 bool Gecko_FallibleAssignCString(nsACString* aThis, const nsACString* aOther)
 {
   return aThis->Assign(*aOther, mozilla::fallible);
 }
 
+bool Gecko_FallibleTakeFromCString(nsACString* aThis, nsACString* aOther)
+{
+  return aThis->Assign(mozilla::Move(*aOther), mozilla::fallible);
+}
+
 bool Gecko_FallibleAppendCString(nsACString* aThis, const nsACString* aOther)
 {
   return aThis->Append(*aOther, mozilla::fallible);
 }
 
 bool Gecko_FallibleSetLengthCString(nsACString* aThis, uint32_t aLength)
 {
   return aThis->SetLength(aLength, mozilla::fallible);
@@ -420,31 +430,41 @@ void Gecko_FinalizeString(nsAString* aTh
   aThis->~nsAString();
 }
 
 void Gecko_AssignString(nsAString* aThis, const nsAString* aOther)
 {
   aThis->Assign(*aOther);
 }
 
+void Gecko_TakeFromString(nsAString* aThis, nsAString* aOther)
+{
+  aThis->Assign(mozilla::Move(*aOther));
+}
+
 void Gecko_AppendString(nsAString* aThis, const nsAString* aOther)
 {
   aThis->Append(*aOther);
 }
 
 void Gecko_SetLengthString(nsAString* aThis, uint32_t aLength)
 {
   aThis->SetLength(aLength);
 }
 
 bool Gecko_FallibleAssignString(nsAString* aThis, const nsAString* aOther)
 {
   return aThis->Assign(*aOther, mozilla::fallible);
 }
 
+bool Gecko_FallibleTakeFromString(nsAString* aThis, nsAString* aOther)
+{
+  return aThis->Assign(mozilla::Move(*aOther), mozilla::fallible);
+}
+
 bool Gecko_FallibleAppendString(nsAString* aThis, const nsAString* aOther)
 {
   return aThis->Append(*aOther, mozilla::fallible);
 }
 
 bool Gecko_FallibleSetLengthString(nsAString* aThis, uint32_t aLength)
 {
   return aThis->SetLength(aLength, mozilla::fallible);