Closed Bug 1041822 Opened 10 years ago Closed 10 years ago

Add a lookupOrAdd to nsClassHashtable

Categories

(Core :: XPCOM, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla34

People

(Reporter: mrbkap, Assigned: mrbkap)

References

Details

Attachments

(1 file)

Currently, there's no way to avoid having to do two lookups when using an nsClassHashtable if I want to look up an object that may have already been created that I then want to modify. This operation is easy to do using PLDHashTable (operate using PL_DHASH_ADD and use the resulting array).

For nsClassHashtable, we could add this functionality pretty easily. Its users would have to have a default constructor, but IMO we could live with that. Is there a reason that we haven't done this before?
Attached patch patch v1Splinter Review
I didn't add an infallible version of this, but one could be added pretty easily.

Is there any reason not to do this?
Attachment #8459910 - Flags: review?(benjamin)
s/infallible/fallible/
You might have better luck with a review from :froydnj, as I think bsmedberg is away for another week or so.
Comment on attachment 8459910 [details] [diff] [review]
patch v1

The magic of templates means that this only has to compile if somebody uses it. This is fine. I wonder if we should do something similar for nsDataHashtable, but I guess we don't need to until somebody needs it there.
Attachment #8459910 - Flags: review?(benjamin) → review+
Blocks: 1051102
Assignee: nobody → mrbkap
https://hg.mozilla.org/mozilla-central/rev/d20cfaa4220b
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla34
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: