Bug 1203680 P2 Implement an NS_InputStreamIsCloneable() method. r=froydnj
authorBen Kelly <ben@wanderview.com>
Tue, 15 Sep 2015 10:15:45 -0700
changeset 262613 4d35af8a3b5db8b1dc25bddf4b38ef15ee3253f8
parent 262612 1231d6e5af3e7e94fdadc48f04466d5164f00ee5
child 262614 278ddd4793c39195bbf156bb70b6838d845ea04a
push id15198
push userkwierso@gmail.com
push dateWed, 16 Sep 2015 00:21:31 +0000
treeherderfx-team@dbfddd6efb5d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1203680
milestone43.0a1
Bug 1203680 P2 Implement an NS_InputStreamIsCloneable() method. r=froydnj
xpcom/io/nsStreamUtils.cpp
xpcom/io/nsStreamUtils.h
--- a/xpcom/io/nsStreamUtils.cpp
+++ b/xpcom/io/nsStreamUtils.cpp
@@ -852,16 +852,27 @@ NS_FillArray(FallibleTArray<char>& aDest
   // SetLengthAndRetainStorage here, see nsTArrayElementTraits::Construct()
   // in nsTArray.h:
   aDest.SetLengthAndRetainStorage(aKeep + *aNewBytes);
 
   MOZ_ASSERT(aDest.Length() <= aDest.Capacity(), "buffer overflow");
   return rv;
 }
 
+bool
+NS_InputStreamIsCloneable(nsIInputStream* aSource)
+{
+  if (!aSource) {
+    return false;
+  }
+
+  nsCOMPtr<nsICloneableInputStream> cloneable = do_QueryInterface(aSource);
+  return cloneable && cloneable->GetCloneable();
+}
+
 nsresult
 NS_CloneInputStream(nsIInputStream* aSource, nsIInputStream** aCloneOut,
                     nsIInputStream** aReplacementOut)
 {
   if (NS_WARN_IF(!aSource)) {
     return NS_ERROR_FAILURE;
   }
 
--- a/xpcom/io/nsStreamUtils.h
+++ b/xpcom/io/nsStreamUtils.h
@@ -260,16 +260,22 @@ struct MOZ_STACK_CLASS nsWriteSegmentThu
  *        failed
  * @return the result from aInput->Read(...)
  */
 extern NS_METHOD
 NS_FillArray(FallibleTArray<char>& aDest, nsIInputStream* aInput,
              uint32_t aKeep, uint32_t* aNewBytes);
 
 /**
+ * Return true if the given stream can be directly cloned.
+ */
+extern bool
+NS_InputStreamIsCloneable(nsIInputStream* aSource);
+
+/**
  * Clone the provided source stream in the most efficient way possible.  This
  * first attempts to QI to nsICloneableInputStream to use Clone().  If that is
  * not supported or its cloneable attribute is false, then a fallback clone is
  * provided by copying the source to a pipe.  In this case the caller must
  * replace the source stream with the resulting replacement stream.  The clone
  * and the replacement stream are then cloneable using nsICloneableInputStream
  * without duplicating memory.  This fallback clone using the pipe is only
  * performed if a replacement stream parameter is also passed in.