Bug 1223808 - part 2 - use UniquePtr<uint8_t[]> instead of nsAutoArrayPtr<SHA1Sum::Hash> in HandleHashKey; r=michal

This commit is contained in:
Nathan Froyd 2015-11-18 15:56:47 -05:00
parent c15363929c
commit d1a487b2e4
2 changed files with 13 additions and 6 deletions

View File

@ -320,7 +320,7 @@ CacheFileHandles::HandleHashKey::SizeOfExcludingThis(mozilla::MallocSizeOf mallo
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
size_t n = 0;
n += mallocSizeOf(mHash);
n += mallocSizeOf(mHash.get());
for (uint32_t i = 0; i < mHandles.Length(); ++i) {
n += mHandles[i]->SizeOfIncludingThis(mallocSizeOf);
}

View File

@ -142,8 +142,8 @@ public:
explicit HandleHashKey(KeyTypePointer aKey)
{
MOZ_COUNT_CTOR(HandleHashKey);
mHash = (SHA1Sum::Hash*)new uint8_t[SHA1Sum::kHashSize];
memcpy(mHash, aKey, sizeof(SHA1Sum::Hash));
mHash = MakeUnique<uint8_t[]>(SHA1Sum::kHashSize);
memcpy(mHash.get(), aKey, sizeof(SHA1Sum::Hash));
}
HandleHashKey(const HandleHashKey& aOther)
{
@ -156,7 +156,7 @@ public:
bool KeyEquals(KeyTypePointer aKey) const
{
return memcmp(mHash, aKey, sizeof(SHA1Sum::Hash)) == 0;
return memcmp(mHash.get(), aKey, sizeof(SHA1Sum::Hash)) == 0;
}
static KeyTypePointer KeyToPointer(KeyType aKey)
{
@ -172,7 +172,10 @@ public:
already_AddRefed<CacheFileHandle> GetNewestHandle();
void GetHandles(nsTArray<RefPtr<CacheFileHandle> > &aResult);
SHA1Sum::Hash *Hash() const { return mHash; }
SHA1Sum::Hash *Hash() const
{
return reinterpret_cast<SHA1Sum::Hash*>(mHash.get());
}
bool IsEmpty() const { return mHandles.Length() == 0; }
enum { ALLOW_MEMMOVE = true };
@ -186,7 +189,11 @@ public:
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
private:
nsAutoArrayPtr<SHA1Sum::Hash> mHash;
// We can't make this UniquePtr<SHA1Sum::Hash>, because you can't have
// UniquePtrs with known bounds. So we settle for this representation
// and using appropriate casts when we need to access it as a
// SHA1Sum::Hash.
UniquePtr<uint8_t[]> mHash;
// Use weak pointers since the hash table access is on a single thread
// only and CacheFileHandle removes itself from this table in its dtor
// that may only be called on the same thread as we work with the hashtable