Add a lookupOrAdd to nsClassHashtable

RESOLVED FIXED in mozilla34

Status

()

RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: mrbkap, Assigned: mrbkap)

Tracking

unspecified
mozilla34
x86_64
Linux
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

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?
Created attachment 8459910 [details] [diff] [review]
patch v1

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 4

5 years ago
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+
Assignee: nobody → mrbkap
https://hg.mozilla.org/mozilla-central/rev/d20cfaa4220b
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla34
You need to log in before you can comment on or make changes to this bug.