Bug 819090 - Replace nsVoidArray with nsTArray in netwerk/cache/. r=michal

This commit is contained in:
Birunthan Mohanathas 2015-01-19 19:50:16 +02:00
parent 3a46343337
commit 2b65bd6047
3 changed files with 14 additions and 19 deletions

View File

@ -99,7 +99,7 @@ nsCacheEntryDescriptor::~nsCacheEntryDescriptor()
if (mCacheEntry)
Close();
NS_ASSERTION(mInputWrappers.Count() == 0,
NS_ASSERTION(mInputWrappers.IsEmpty(),
"We have still some input wrapper!");
NS_ASSERTION(!mOutputWrapper, "We have still an output wrapper!");
@ -565,9 +565,8 @@ nsCacheEntryDescriptor::Close()
// Make sure no other stream can be opened
mClosingDescriptor = true;
outputWrapper = mOutputWrapper;
for (int32_t i = 0 ; i < mInputWrappers.Count() ; i++)
inputWrappers.AppendElement(static_cast<nsInputStreamWrapper *>(
mInputWrappers[i]));
for (size_t i = 0; i < mInputWrappers.Length(); i++)
inputWrappers.AppendElement(mInputWrappers[i]);
}
// Call Close() on the streams outside the lock since it might need to call
@ -678,7 +677,7 @@ nsCacheEntryDescriptor::nsInputStreamWrapper::Release()
if (0 == count) {
// don't use desc here since mDescriptor might be already nulled out
if (mDescriptor) {
NS_ASSERTION(mDescriptor->mInputWrappers.IndexOf(this) != -1,
NS_ASSERTION(mDescriptor->mInputWrappers.Contains(this),
"Wrapper not found in array!");
mDescriptor->mInputWrappers.RemoveElement(this);
}
@ -872,7 +871,7 @@ nsCacheEntryDescriptor::nsDecompressInputStreamWrapper::Release()
if (0 == count) {
// don't use desc here since mDescriptor might be already nulled out
if (mDescriptor) {
NS_ASSERTION(mDescriptor->mInputWrappers.IndexOf(this) != -1,
NS_ASSERTION(mDescriptor->mInputWrappers.Contains(this),
"Wrapper not found in array!");
mDescriptor->mInputWrappers.RemoveElement(this);
}

View File

@ -15,7 +15,6 @@
#include "nsCacheService.h"
#include "zlib.h"
#include "mozilla/Mutex.h"
#include "nsVoidArray.h"
/******************************************************************************
* nsCacheEntryDescriptor
@ -45,7 +44,7 @@ public:
nsCacheEntry * CacheEntry(void) { return mCacheEntry; }
bool ClearCacheEntry(void)
{
NS_ASSERTION(mInputWrappers.Count() == 0, "Bad state");
NS_ASSERTION(mInputWrappers.IsEmpty(), "Bad state");
NS_ASSERTION(!mOutputWrapper, "Bad state");
bool doomEntry = false;
@ -226,7 +225,7 @@ private:
*/
nsCacheEntry * mCacheEntry; // we are a child of the entry
nsCacheAccessMode mAccessGranted;
nsVoidArray mInputWrappers;
nsTArray<nsInputStreamWrapper*> mInputWrappers;
nsOutputStreamWrapper * mOutputWrapper;
mozilla::Mutex mLock;
bool mAsyncDoomPending;

View File

@ -33,7 +33,6 @@
#include "nsAppDirectoryServiceDefs.h"
#include "nsThreadUtils.h"
#include "nsProxyRelease.h"
#include "nsVoidArray.h"
#include "nsDeleteDir.h"
#include "nsNetCID.h"
#include <math.h> // for log()
@ -2967,7 +2966,7 @@ nsCacheService::GetActiveEntries(PLDHashTable * table,
uint32_t number,
void * arg)
{
static_cast<nsVoidArray *>(arg)->AppendElement(
static_cast<nsTArray<nsCacheEntry*>*>(arg)->AppendElement(
((nsCacheEntryHashTableEntry *)hdr)->cacheEntry);
return PL_DHASH_NEXT;
}
@ -3022,12 +3021,12 @@ nsCacheService::CloseAllStreams()
{
nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_CLOSEALLSTREAMS));
nsVoidArray entries;
nsTArray<nsCacheEntry*> entries;
#if DEBUG
// make sure there is no active entry
mActiveEntries.VisitEntries(GetActiveEntries, &entries);
NS_ASSERTION(entries.Count() == 0, "Bad state");
NS_ASSERTION(entries.IsEmpty(), "Bad state");
#endif
// Get doomed entries
@ -3039,8 +3038,8 @@ nsCacheService::CloseAllStreams()
}
// Iterate through all entries and collect input and output streams
for (int32_t i = 0 ; i < entries.Count() ; i++) {
entry = static_cast<nsCacheEntry *>(entries.ElementAt(i));
for (size_t i = 0; i < entries.Length(); i++) {
entry = entries.ElementAt(i);
nsTArray<nsRefPtr<nsCacheEntryDescriptor> > descs;
entry->GetDescriptors(descs);
@ -3049,10 +3048,8 @@ nsCacheService::CloseAllStreams()
if (descs[j]->mOutputWrapper)
outputs.AppendElement(descs[j]->mOutputWrapper);
for (int32_t k = 0 ; k < descs[j]->mInputWrappers.Count() ; k++)
inputs.AppendElement(static_cast<
nsCacheEntryDescriptor::nsInputStreamWrapper *>(
descs[j]->mInputWrappers[k]));
for (size_t k = 0; k < descs[j]->mInputWrappers.Length(); k++)
inputs.AppendElement(descs[j]->mInputWrappers[k]);
}
}
}