Bug 1093357 P2 Implement an NS_InputStreamIsCloneable() method. r=froydnj
☠☠ backed out by 21b8c95e507a ☠ ☠
authorBen Kelly <ben@wanderview.com>
Mon, 14 Sep 2015 12:04:56 -0700
changeset 295017 b25230c0a193679868576ac673aacabd6ef79b98
parent 295016 2369d63ef14a58fd2ccaf95b7f24747f75e47642
child 295018 6fedc85dc0d905a5a8deb3782d138cef68476178
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1093357
milestone43.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 1093357 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.