Bug 1339710 - Remove the implementation of SlicedInputStream::ReadSegmenets, r=smaug
☠☠ backed out by 94e98e7e3227 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 22 Feb 2017 07:57:54 +0100
changeset 373230 7c0ec55b44dc159a6eb0c9ff65b922952e6e4f11
parent 373229 cbb4e1c2aada22f98894e2fe94ef9a0e7bde4293
child 373231 4a24f274ec59f962bbe1bce06b41a537205abf34
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1339710
milestone54.0a1
Bug 1339710 - Remove the implementation of SlicedInputStream::ReadSegmenets, r=smaug
xpcom/io/SlicedInputStream.cpp
--- a/xpcom/io/SlicedInputStream.cpp
+++ b/xpcom/io/SlicedInputStream.cpp
@@ -116,35 +116,19 @@ SlicedInputStream::Available(uint64_t* a
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 SlicedInputStream::Read(char* aBuffer, uint32_t aCount, uint32_t* aReadCount)
 {
-  return ReadSegments(NS_CopySegmentToBuffer, aBuffer, aCount, aReadCount);
-}
-
-NS_IMETHODIMP
-SlicedInputStream::ReadSegments(nsWriteSegmentFun aWriter, void* aClosure,
-                                uint32_t aCount, uint32_t *aResult)
-{
-  NS_ENSURE_STATE(mInputStream);
-
-  uint32_t result;
-
-  if (!aResult) {
-    aResult = &result;
-  }
-
-  *aResult = 0;
-
   if (mClosed) {
-    return NS_BASE_STREAM_CLOSED;
+    *aReadCount = 0;
+    return NS_OK;
   }
 
   if (mCurPos < mStart) {
     nsCOMPtr<nsISeekableStream> seekableStream =
       do_QueryInterface(mInputStream);
     if (seekableStream) {
       nsresult rv = seekableStream->Seek(nsISeekableStream::NS_SEEK_SET,
                                          mStart);
@@ -168,46 +152,33 @@ SlicedInputStream::ReadSegments(nsWriteS
     }
   }
 
   // Let's reduce aCount in case it's too big.
   if (mCurPos + aCount > mStart + mLength) {
     aCount = mStart + mLength - mCurPos;
   }
 
-  char buf[4096];
-  while (mCurPos < mStart + mLength && *aResult < aCount) {
-    uint32_t bytesRead;
-    uint64_t bufCount = XPCOM_MIN(aCount - *aResult, (uint32_t)sizeof(buf));
-    nsresult rv = mInputStream->Read(buf, bufCount, &bytesRead);
-    if (NS_WARN_IF(NS_FAILED(rv)) || bytesRead == 0) {
-      return rv;
-    }
-
-    mCurPos += bytesRead;
-
-    uint32_t bytesWritten = 0;
-    while (bytesWritten < bytesRead) {
-      uint32_t writerCount = 0;
-      rv = aWriter(this, aClosure, buf + bytesWritten, *aResult,
-                   bytesRead - bytesWritten, &writerCount);
-      if (NS_FAILED(rv) || writerCount == 0) {
-	return NS_OK;
-      }
-
-      MOZ_ASSERT(writerCount <= bytesRead - bytesWritten);
-      bytesWritten += writerCount;
-      *aResult += writerCount;
-    }
+  nsresult rv = mInputStream->Read(aBuffer, aCount, aReadCount);
+  if (NS_WARN_IF(NS_FAILED(rv)) || *aReadCount == 0) {
+    return rv;
   }
 
+  mCurPos += *aReadCount;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+SlicedInputStream::ReadSegments(nsWriteSegmentFun aWriter, void* aClosure,
+                                uint32_t aCount, uint32_t *aResult)
+{
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
 SlicedInputStream::IsNonBlocking(bool* aNonBlocking)
 {
   NS_ENSURE_STATE(mInputStream);
   return mInputStream->IsNonBlocking(aNonBlocking);
 }
 
 // nsICloneableInputStream interface