Bug 1368837 - Replace debugging ReadAt with CachedReadAt code - r=cpearce
authorGerald Squelart <gsquelart@mozilla.com>
Mon, 29 May 2017 13:36:27 +1200
changeset 361723 cc5eaeefd44520822edf91a49355d354d6f38ad5
parent 361722 b3dff4b28a95446bdae8c91e15ec1a5b5ab5b6c7
child 361724 30a1c114fe232099815361fbef331468abf44041
push id31939
push usercbook@mozilla.com
push dateThu, 01 Jun 2017 11:49:28 +0000
treeherdermozilla-central@d96110d76619 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1368837
milestone55.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 1368837 - Replace debugging ReadAt with CachedReadAt code - r=cpearce MozReview-Commit-ID: 88j9oAPdI0w
dom/media/MediaResource.cpp
dom/media/MediaResource.h
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -1652,89 +1652,16 @@ ResultName(nsresult aResult)
 }
 
 nsresult
 MediaResourceIndex::ReadAt(int64_t aOffset,
                            char* aBuffer,
                            uint32_t aCount,
                            uint32_t* aBytes)
 {
-  const int oOffset = int(aOffset);
-  const unsigned oCount = unsigned(aCount);
-  nsresult rvu = UncachedReadAt(aOffset, aBuffer, aCount, aBytes);
-  printf("**** [%p]CompareReadAt(%u@%d) UncachedReadAt -> %s, %u\n",
-         this,
-         oCount,
-         oOffset,
-         ResultName(rvu).get(),
-         *aBytes);
-
-  printf("**** [%p]CompareReadAt(%u@%d) CachedReadAt: ----------------\n",
-         this,
-         oCount,
-         oOffset);
-  char* buf = new char[aCount];
-  uint32_t bytes = 0;
-  nsresult rvc = CachedReadAt(aOffset, buf, aCount, &bytes);
-
-  printf("**** [%p]CompareReadAt(%u@%d) ---------------- Comparing...\n",
-         this,
-         oCount,
-         oOffset);
-
-  if (rvu != rvc) {
-    printf("*** read(aOffset=%d, aCount=%u) - rvu=%s != rvc=%s\n",
-           int(aOffset),
-           unsigned(aCount),
-           ResultName(rvu).get(),
-           ResultName(rvc).get());
-    MOZ_ASSERT(rvu == rvc || rvc == NS_OK);
-    if (rvc == NS_OK) {
-      // Cached read wins!
-      *aBytes = bytes;
-      memcpy(aBuffer, buf, bytes);
-    }
-  } else if (NS_SUCCEEDED(rvu)) {
-    if (*aBytes != bytes) {
-      printf("*** read(aOffset=%d, aCount=%u) - bu=%u != bc=%u\n",
-             int(aOffset),
-             unsigned(aCount),
-             unsigned(*aBytes),
-             unsigned(bytes));
-      MOZ_ASSERT(*aBytes == bytes);
-    } else {
-      for (uint32_t i = 0; i < bytes; ++i) {
-        uint8_t bu = uint8_t(aBuffer[i]);
-        uint8_t bc = uint8_t(buf[i]);
-        if (bu != bc) {
-          printf("*** read(aOffset=%d, aCount=%u) - u[%u]=%u != c[%u]=%u\n",
-                 int(aOffset),
-                 unsigned(aCount),
-                 unsigned(i),
-                 unsigned(bu),
-                 unsigned(i),
-                 unsigned(bc));
-          MOZ_ASSERT(bu == bc);
-          break;
-        }
-      }
-    }
-  }
-
-  delete[] buf;
-
-  return rvc;
-}
-
-nsresult
-MediaResourceIndex::CachedReadAt(int64_t aOffset,
-                                 char* aBuffer,
-                                 uint32_t aCount,
-                                 uint32_t* aBytes)
-{
   if (mCacheBlockSize == 0) {
     return UncachedReadAt(aOffset, aBuffer, aCount, aBytes);
   }
 
   const int oOffset = int(aOffset);
   const unsigned oCount = unsigned(aCount);
   *aBytes = 0;
 
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -809,28 +809,26 @@ public:
   MediaResource* GetResource() const { return mResource; }
 
   // Read up to aCount bytes from the stream. The read starts at
   // aOffset in the stream, seeking to that location initially if
   // it is not the current stream offset.
   // Unlike MediaResource::ReadAt, ReadAt only returns fewer bytes than
   // requested if end of stream or an error is encountered. There is no need to
   // call it again to get more data.
+  // If the resource has cached data past the end of the request, it will be
+  // used to fill a local cache, which should speed up consecutive ReadAt's
+  // (mostly by avoiding using the resource's IOs and locks.)
   // *aBytes will contain the number of bytes copied, even if an error occurred.
   // ReadAt doesn't have an impact on the offset returned by Tell().
   nsresult ReadAt(int64_t aOffset,
                   char* aBuffer,
                   uint32_t aCount,
                   uint32_t* aBytes);
 
-  nsresult CachedReadAt(int64_t aOffset,
-                        char* aBuffer,
-                        uint32_t aCount,
-                        uint32_t* aBytes);
-
   // Same as ReadAt, but doesn't try to cache around the read.
   // Useful if you know that you will not read again from the same area.
   nsresult UncachedReadAt(int64_t aOffset,
                           char* aBuffer,
                           uint32_t aCount,
                           uint32_t* aBytes) const;
 
   // Convenience methods, directly calling the MediaResource method of the same