Bug 1475461 - part 2: Make callers of PLDHashTable::Search() const methods if possible r=Ehsan

Some callers of PLDHashTable::Search() use const_cast, some others are not
const methods due to non-const PLDHashTable::Search().

This patch removes const_cast from the former and mark some methods of the
latter const.

MozReview-Commit-ID: C8ayoi7mXc1

--HG--
extra : rebase_source : 2cba0339756e3278ba6e5f0e8a11e68217a61d34
This commit is contained in:
Masayuki Nakano 2018-07-13 19:01:53 +09:00
parent 78077d5b3c
commit 5c3723acb2
13 changed files with 21 additions and 21 deletions

View file

@ -295,8 +295,7 @@ nsCommandParams::RemoveValue(const char* aName)
nsCommandParams::HashEntry* nsCommandParams::HashEntry*
nsCommandParams::GetNamedEntry(const char* aName) const nsCommandParams::GetNamedEntry(const char* aName) const
{ {
return static_cast<HashEntry*>( return static_cast<HashEntry*>(mValuesHash.Search((void*)aName));
const_cast<PLDHashTable&>(mValuesHash).Search((void*)aName));
} }
nsCommandParams::HashEntry* nsCommandParams::HashEntry*

View file

@ -112,7 +112,7 @@ public:
static Native2WrappedNativeMap* newMap(int length); static Native2WrappedNativeMap* newMap(int length);
inline XPCWrappedNative* Find(nsISupports* Obj) inline XPCWrappedNative* Find(nsISupports* Obj) const
{ {
MOZ_ASSERT(Obj,"bad param"); MOZ_ASSERT(Obj,"bad param");
auto entry = static_cast<Entry*>(mTable.Search(Obj)); auto entry = static_cast<Entry*>(mTable.Search(Obj));
@ -178,7 +178,7 @@ public:
static IID2WrappedJSClassMap* newMap(int length); static IID2WrappedJSClassMap* newMap(int length);
inline nsXPCWrappedJSClass* Find(REFNSIID iid) inline nsXPCWrappedJSClass* Find(REFNSIID iid) const
{ {
auto entry = static_cast<Entry*>(mTable.Search(&iid)); auto entry = static_cast<Entry*>(mTable.Search(&iid));
return entry ? entry->value : nullptr; return entry ? entry->value : nullptr;
@ -232,7 +232,7 @@ public:
static IID2NativeInterfaceMap* newMap(int length); static IID2NativeInterfaceMap* newMap(int length);
inline XPCNativeInterface* Find(REFNSIID iid) inline XPCNativeInterface* Find(REFNSIID iid) const
{ {
auto entry = static_cast<Entry*>(mTable.Search(&iid)); auto entry = static_cast<Entry*>(mTable.Search(&iid));
return entry ? entry->value : nullptr; return entry ? entry->value : nullptr;
@ -290,7 +290,7 @@ public:
static ClassInfo2NativeSetMap* newMap(int length); static ClassInfo2NativeSetMap* newMap(int length);
inline XPCNativeSet* Find(nsIClassInfo* info) inline XPCNativeSet* Find(nsIClassInfo* info) const
{ {
auto entry = static_cast<Entry*>(mTable.Search(info)); auto entry = static_cast<Entry*>(mTable.Search(info));
return entry ? entry->value : nullptr; return entry ? entry->value : nullptr;
@ -343,7 +343,7 @@ public:
static ClassInfo2WrappedNativeProtoMap* newMap(int length); static ClassInfo2WrappedNativeProtoMap* newMap(int length);
inline XPCWrappedNativeProto* Find(nsIClassInfo* info) inline XPCWrappedNativeProto* Find(nsIClassInfo* info) const
{ {
auto entry = static_cast<Entry*>(mTable.Search(info)); auto entry = static_cast<Entry*>(mTable.Search(info));
return entry ? entry->value : nullptr; return entry ? entry->value : nullptr;
@ -401,7 +401,7 @@ public:
static NativeSetMap* newMap(int length); static NativeSetMap* newMap(int length);
inline XPCNativeSet* Find(XPCNativeSetKey* key) inline XPCNativeSet* Find(XPCNativeSetKey* key) const
{ {
auto entry = static_cast<Entry*>(mTable.Search(key)); auto entry = static_cast<Entry*>(mTable.Search(key));
return entry ? entry->key_value : nullptr; return entry ? entry->key_value : nullptr;

View file

@ -422,7 +422,7 @@ nsCacheEntryHashTable::Shutdown()
nsCacheEntry * nsCacheEntry *
nsCacheEntryHashTable::GetEntry( const nsCString * key) nsCacheEntryHashTable::GetEntry( const nsCString * key) const
{ {
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized"); NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
if (!initialized) return nullptr; if (!initialized) return nullptr;

View file

@ -270,7 +270,7 @@ public:
void Init(); void Init();
void Shutdown(); void Shutdown();
nsCacheEntry *GetEntry( const nsCString * key); nsCacheEntry *GetEntry( const nsCString * key) const;
nsresult AddEntry( nsCacheEntry *entry); nsresult AddEntry( nsCacheEntry *entry);
void RemoveEntry( nsCacheEntry *entry); void RemoveEntry( nsCacheEntry *entry);

View file

@ -192,7 +192,7 @@ nsDiskCacheBindery::CreateBinding(nsCacheEntry * entry,
* FindActiveEntry : to find active colliding entry so we can doom it * FindActiveEntry : to find active colliding entry so we can doom it
*/ */
nsDiskCacheBinding * nsDiskCacheBinding *
nsDiskCacheBindery::FindActiveBinding(uint32_t hashNumber) nsDiskCacheBindery::FindActiveBinding(uint32_t hashNumber) const
{ {
NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized"); NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
// find hash entry for key // find hash entry for key

View file

@ -103,7 +103,7 @@ public:
nsDiskCacheBinding * CreateBinding(nsCacheEntry * entry, nsDiskCacheBinding * CreateBinding(nsCacheEntry * entry,
nsDiskCacheRecord * record); nsDiskCacheRecord * record);
nsDiskCacheBinding * FindActiveBinding(uint32_t hashNumber); nsDiskCacheBinding * FindActiveBinding(uint32_t hashNumber) const;
void RemoveBinding(nsDiskCacheBinding * binding); void RemoveBinding(nsDiskCacheBinding * binding);
bool ActiveBindings(); bool ActiveBindings();

View file

@ -1396,7 +1396,8 @@ void nsDocLoader::RemoveRequestInfo(nsIRequest *aRequest)
mRequestInfoHash.Remove(aRequest); mRequestInfoHash.Remove(aRequest);
} }
nsDocLoader::nsRequestInfo* nsDocLoader::GetRequestInfo(nsIRequest* aRequest) nsDocLoader::nsRequestInfo*
nsDocLoader::GetRequestInfo(nsIRequest* aRequest) const
{ {
return static_cast<nsRequestInfo*>(mRequestInfoHash.Search(aRequest)); return static_cast<nsRequestInfo*>(mRequestInfoHash.Search(aRequest));
} }

View file

@ -325,7 +325,7 @@ private:
nsresult AddRequestInfo(nsIRequest* aRequest); nsresult AddRequestInfo(nsIRequest* aRequest);
void RemoveRequestInfo(nsIRequest* aRequest); void RemoveRequestInfo(nsIRequest* aRequest);
nsRequestInfo *GetRequestInfo(nsIRequest* aRequest); nsRequestInfo *GetRequestInfo(nsIRequest* aRequest) const;
void ClearRequestInfoHash(); void ClearRequestInfoHash();
int64_t CalculateMaxProgress(); int64_t CalculateMaxProgress();
/// void DumpChannelInfo(void); /// void DumpChannelInfo(void);

View file

@ -956,7 +956,7 @@ public:
} }
private: private:
PtrToNodeEntry* FindNodeEntry(void* aPtr) PtrToNodeEntry* FindNodeEntry(void* aPtr) const
{ {
return static_cast<PtrToNodeEntry*>(mPtrToNodeMap.Search(aPtr)); return static_cast<PtrToNodeEntry*>(mPtrToNodeMap.Search(aPtr));
} }

View file

@ -243,7 +243,7 @@ class nsAtomSubTable
void AddSizeOfExcludingThisLocked(MallocSizeOf aMallocSizeOf, void AddSizeOfExcludingThisLocked(MallocSizeOf aMallocSizeOf,
AtomsSizes& aSizes); AtomsSizes& aSizes);
AtomTableEntry* Search(AtomTableKey& aKey) AtomTableEntry* Search(AtomTableKey& aKey) const
{ {
mLock.AssertCurrentThreadOwns(); mLock.AssertCurrentThreadOwns();
return static_cast<AtomTableEntry*>(mTable.Search(&aKey)); return static_cast<AtomTableEntry*>(mTable.Search(&aKey));

View file

@ -163,7 +163,7 @@ nsStaticCaseInsensitiveNameTable::~nsStaticCaseInsensitiveNameTable()
} }
int32_t int32_t
nsStaticCaseInsensitiveNameTable::Lookup(const nsACString& aName) nsStaticCaseInsensitiveNameTable::Lookup(const nsACString& aName) const
{ {
NS_ASSERTION(mNameArray, "not inited"); NS_ASSERTION(mNameArray, "not inited");
@ -176,7 +176,7 @@ nsStaticCaseInsensitiveNameTable::Lookup(const nsACString& aName)
} }
int32_t int32_t
nsStaticCaseInsensitiveNameTable::Lookup(const nsAString& aName) nsStaticCaseInsensitiveNameTable::Lookup(const nsAString& aName) const
{ {
NS_ASSERTION(mNameArray, "not inited"); NS_ASSERTION(mNameArray, "not inited");

View file

@ -33,8 +33,8 @@ class nsStaticCaseInsensitiveNameTable
public: public:
enum { NOT_FOUND = -1 }; enum { NOT_FOUND = -1 };
int32_t Lookup(const nsACString& aName); int32_t Lookup(const nsACString& aName) const;
int32_t Lookup(const nsAString& aName); int32_t Lookup(const nsAString& aName) const;
const nsCString& GetStringValue(int32_t aIndex); const nsCString& GetStringValue(int32_t aIndex);
nsStaticCaseInsensitiveNameTable(const char* const aNames[], int32_t aLength); nsStaticCaseInsensitiveNameTable(const char* const aNames[], int32_t aLength);

View file

@ -132,7 +132,7 @@ public:
EntryType* GetEntry(KeyType aKey) const EntryType* GetEntry(KeyType aKey) const
{ {
return static_cast<EntryType*>( return static_cast<EntryType*>(
const_cast<PLDHashTable*>(&mTable)->Search(EntryType::KeyToPointer(aKey))); mTable.Search(EntryType::KeyToPointer(aKey)));
} }
/** /**