Open Bug 1006208 Opened 10 years ago Updated 2 years ago

nsTHashtable::SizeOfEntryExcludingThisFun should use a reference instead of a pointer

Categories

(Core :: XPCOM, defect)

defect

Tracking

()

People

(Reporter: erahm, Unassigned)

References

Details

In https://bugzilla.mozilla.org/show_bug.cgi?id=1003479#c6 there was a consensus that switching |nsTHashtable::SizeOfEntryExcludingThisFun| over to taking a reference the the hash table entry rather than a pointer would be helpful in that: 1) It would help avoid accidentally doing |entry->SizeOfIncludingThis| 2) It would make it easier for us to find instances of |blah->SizeOfExcludingThis| that should be |blah->SizeOfIncludingThis| It would be nice to do this for |PLDHashSizeOfEntryExcludingThisFun| as well, but that's less feasible as that is passing a generic pointer around that is eventually cast to the actual type. As an improvement we could modify existing instances[1] of |PLDHashSizeOfEntryExcludingThisFun| to cast to a ref rather than a pointer. My proposal is as follows: * Modify |nsTHashtable::SizeOfEntryExcludingThisFun| to take |EntryType&| instead of |EntryType*| * Update all instances of |nsTHashtable::SizeOfEntryExcludingThisFun| to use the new parameter type [2] * Update all existing |PLDHashSizeOfEntryExcludingThisFun| instances to cast to a reference instead of a pointer, ie |Type& type = *static_cast<Type*>(entry);| [1] http://dxr.mozilla.org/mozilla-central/search?q=PL_DHashTableSizeOfExcludingThis&case=true [2] http://dxr.mozilla.org/mozilla-central/search?q=%2Bfunction-ref%3A%22nsTHashtable%3A%3ASizeOfExcludingThis%28SizeOfEntryExcludingThisFun%2C+mozilla%3A%3AMallocSizeOf%2C+void+*%29+const%22
Whiteboard: [MemShrink]
Whiteboard: [MemShrink]
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.