Bug 1368837 - Replace debugging ReadAt with CachedReadAt code - r=cpearce

MozReview-Commit-ID: 88j9oAPdI0w

--HG--
extra : rebase_source : 7bf1da0b98eeaa871809c5c7386a7a26f99c7f29
This commit is contained in:
Gerald Squelart 2017-05-29 13:36:27 +12:00
Родитель 1bb5358dcf
Коммит 0a2dc3ad21
2 изменённых файлов: 3 добавлений и 78 удалений

Просмотреть файл

@ -1656,79 +1656,6 @@ 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);

Просмотреть файл

@ -814,6 +814,9 @@ public:
// 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,
@ -821,11 +824,6 @@ public:
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,