Bug 1124973 (part 5) - Use PL_DHashTableSearch() in gfxFT2FontList.cpp. r=froydnj,jkew.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 26 Jan 2015 14:25:13 -0800
changeset 239567 332e69cd3273c05f1c75cb85d37d80dc3f69f1ce
parent 239566 fc7c269f2b7a7f2a9b55554c6961ccd156b475cf
child 239568 fd36ee6e8307bfe6e5ff49adb1ac64ccca5cf3dc
push id500
push userjoshua.m.grant@gmail.com
push dateThu, 29 Jan 2015 01:48:36 +0000
reviewersfroydnj, jkew
bugs1124973
milestone38.0a1
Bug 1124973 (part 5) - Use PL_DHashTableSearch() in gfxFT2FontList.cpp. r=froydnj,jkew. Because PL_DHashTableLookup() never returns null, GetInfoForFile() features not one but *two* can-never-fail null checks on its result. Having said that, the code as written works, at least for non-zero-sized files, because |entry->mFileSize| will always be zero if the lookup fails (thanks to PLDHashTable always being zeroed at construction, and |mMap| using PL_DHashClearEntryStub which also zeroes). But for zero-sized files the current code will act like they don't exist. Maybe this can't happen in practice, but it seems dangerous and so I've changed it so the new code will treat zero-sized files just like non-zero-sized files.
gfx/thebes/gfxFT2FontList.cpp
--- a/gfx/thebes/gfxFT2FontList.cpp
+++ b/gfx/thebes/gfxFT2FontList.cpp
@@ -710,23 +710,20 @@ public:
 
     virtual void
     GetInfoForFile(const nsCString& aFileName, nsCString& aFaceList,
                    uint32_t *aTimestamp, uint32_t *aFilesize)
     {
         if (!mMap.IsInitialized()) {
             return;
         }
-        PLDHashEntryHdr *hdr =
-            PL_DHashTableLookup(&mMap, aFileName.get());
-        if (!hdr) {
-            return;
-        }
-        FNCMapEntry* entry = static_cast<FNCMapEntry*>(hdr);
-        if (entry && entry->mFilesize) {
+        FNCMapEntry *entry =
+            static_cast<FNCMapEntry*>(PL_DHashTableSearch(&mMap,
+                                                          aFileName.get()));
+        if (entry) {
             *aTimestamp = entry->mTimestamp;
             *aFilesize = entry->mFilesize;
             aFaceList.Assign(entry->mFaces);
             // this entry does correspond to an existing file
             // (although it might not be up-to-date, in which case
             // it will get overwritten via CacheFileInfo)
             entry->mFileExists = true;
         }