Bug 1413901 - Move rust-url-capi.h include in the MozURL.cpp, r=valentin
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 02 Nov 2017 19:14:41 +0100
changeset 443142 ecf551e606ddf88d3052f9351b81abc6bbf926b6
parent 443141 8ea4737e964255bb6ed15c4d3532769432d91d1f
child 443146 b2f459b88cab5525c785a7fa70a01be3e9cdcb23
child 443156 c773790077bf23429361cb34df73ca21c7f2bc37
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1413901
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 1413901 - Move rust-url-capi.h include in the MozURL.cpp, r=valentin
netwerk/base/MozURL.cpp
netwerk/base/MozURL.h
--- a/netwerk/base/MozURL.cpp
+++ b/netwerk/base/MozURL.cpp
@@ -1,13 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "MozURL.h"
+#include "rust-url-capi/src/rust-url-capi.h"
 
 namespace mozilla {
 namespace net {
 
 NS_IMPL_ADDREF(MozURL)
 NS_IMPL_RELEASE(MozURL)
 
 /* static */ nsresult
@@ -102,16 +103,23 @@ MozURL::GetRef(nsACString& aRef)
 nsresult
 MozURL::GetOrigin(nsACString& aOrigin)
 {
   return rusturl_get_origin(mURL.get(), &aOrigin);
 }
 
 // MozURL::Mutator
 
+MozURL::Mutator::Mutator(MozURL* url)
+  : mURL(rusturl_clone(url->mURL.get()))
+  , mFinalized(false)
+  , mStatus(NS_OK)
+{
+}
+
 // This macro ensures that the mutator is still valid, meaning it hasn't been
 // finalized, and none of the setters have returned an error code.
 #define ENSURE_VALID()                          \
   PR_BEGIN_MACRO                                \
     if (mFinalized) {                           \
       mStatus = NS_ERROR_NOT_AVAILABLE;         \
     }                                           \
     if (NS_FAILED(mStatus)) {                   \
@@ -201,10 +209,16 @@ MozURL::Mutator::SetRef(const nsACString
 MozURL::Mutator&
 MozURL::Mutator::SetPort(int32_t aPort)
 {
   ENSURE_VALID();
   mStatus = rusturl_set_port_no(mURL.get(), aPort);
   return *this;
 }
 
+void
+MozURL::FreeRustURL::operator()(rusturl* aPtr)
+{
+  rusturl_free(aPtr);
+}
+
 } // namespace net
 } // namespace mozilla
--- a/netwerk/base/MozURL.h
+++ b/netwerk/base/MozURL.h
@@ -1,18 +1,21 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozURL_h__
 #define mozURL_h__
 
-#include "rust-url-capi/src/rust-url-capi.h"
 #include "mozilla/UniquePtr.h"
 
+extern "C" {
+struct rusturl;
+}
+
 namespace mozilla {
 namespace net {
 
 // This class provides a thread-safe, immutable URL parser.
 // As long as there is RefPtr to the object, you may use it on any thread.
 // The constructor is private. One can instantiate the object by
 // calling the Init() method as such:
 //
@@ -57,17 +60,17 @@ public:
 private:
   explicit MozURL(rusturl* rawPtr)
     : mURL(rawPtr)
   {
   }
   virtual ~MozURL() {}
   struct FreeRustURL
   {
-    void operator()(rusturl* aPtr) { rusturl_free(aPtr); }
+    void operator()(rusturl* aPtr);
   };
   mozilla::UniquePtr<rusturl, FreeRustURL> mURL;
 
 public:
   class MOZ_STACK_CLASS Mutator
   {
   public:
     // Calling this method will result in the creation of a new MozURL that
@@ -106,22 +109,17 @@ public:
     // mut.SetScheme("!@#$"); // this would fail
     // if (NS_SUCCEDED(mut.GetStatus())) {
     //   nsAutoCString host(ExpensiveComputing());
     //   rv = mut.SetHostname(host).Finalize(getter_AddRefs(url2));
     // }
     // if (NS_SUCCEEDED(rv)) { /* use url2 */ }
     nsresult GetStatus() { return mStatus; }
   private:
-    explicit Mutator(MozURL* url)
-      : mURL(rusturl_clone(url->mURL.get()))
-      , mFinalized(false)
-      , mStatus(NS_OK)
-    {
-    }
+    explicit Mutator(MozURL* url);
     mozilla::UniquePtr<rusturl, FreeRustURL> mURL;
     bool mFinalized;
     nsresult mStatus;
     friend class MozURL;
   };
 
   Mutator Mutate() { return Mutator(this); }