Closed
Bug 1316119
Opened 6 years ago
Closed 6 years ago
add a GetOrInsert to nsbaseHashtable that returns a reference to the value
Categories
(Core :: XPCOM, defect)
Core
XPCOM
Tracking
()
RESOLVED
FIXED
mozilla53
People
(Reporter: tbsaunde, Assigned: tbsaunde)
References
Details
Attachments
(1 file, 2 obsolete files)
1.19 KB,
patch
|
froydnj
:
review+
lizzard
:
approval-mozilla-aurora+
|
Details | Diff | Splinter Review |
This intends to expose basically the same functionality as operator[] on unordered_map.
Assignee | ||
Comment 1•6 years ago
|
||
This intends to expose basically the same functionality as operator[] on unordered_map.
Attachment #8808792 -
Flags: review?(nfroyd)
![]() |
||
Comment 2•6 years ago
|
||
Comment on attachment 8808792 [details] [diff] [review] add a GetOrInsert to nsbaseHashtable that returns a reference to the value Review of attachment 8808792 [details] [diff] [review]: ----------------------------------------------------------------- I don't think this is correct for things like nsRefPtrHashtable, where you're trying to return a reference to a raw pointer. If we want to provide something like this, it'd be *really* nice if we weren't doing two hashtable lookups for the insert case, but reusing the slot we tried to find earlier.
Attachment #8808792 -
Flags: review?(nfroyd)
Assignee | ||
Comment 3•6 years ago
|
||
(In reply to Nathan Froyd [:froydnj] from comment #2) > Comment on attachment 8808792 [details] [diff] [review] > add a GetOrInsert to nsbaseHashtable that returns a reference to the value > > Review of attachment 8808792 [details] [diff] [review]: > ----------------------------------------------------------------- > > I don't think this is correct for things like nsRefPtrHashtable, where > you're trying to return a reference to a raw pointer. I think that fails to compile because ent->mData is a RefPtr and you can get a Foo* out of that, but you can't convert it to a reference. A quick test seems to confirm that, but there may be some other case where this doesn't work. That said I'd be fine with moving this to nsDataHashtable. > If we want to provide something like this, it'd be *really* nice if we > weren't doing two hashtable lookups for the insert case, but reusing the > slot we tried to find earlier. True, but I don't see an easy way to do that with PLDHash, and I don't really have time at the moment to deal with that :/ That said this seems preferable to the alternative of call twice manually, at least this way when we have time to fix PLDHash we can get all the users for free. I guess I could rewrite the code that needs this to use nsTHashtable directly and build my own mapping stuff, but I'd rather not.
Assignee | ||
Updated•6 years ago
|
Flags: needinfo?(nfroyd)
![]() |
||
Comment 4•6 years ago
|
||
(In reply to Trevor Saunders (:tbsaunde) from comment #3) > (In reply to Nathan Froyd [:froydnj] from comment #2) > > I don't think this is correct for things like nsRefPtrHashtable, where > > you're trying to return a reference to a raw pointer. > > I think that fails to compile because ent->mData is a RefPtr and you can get > a Foo* out of that, but you can't convert it to a reference. A quick test > seems to confirm that, but there may be some other case where this doesn't > work. > > That said I'd be fine with moving this to nsDataHashtable. I guess I'd be OK with that. > > If we want to provide something like this, it'd be *really* nice if we > > weren't doing two hashtable lookups for the insert case, but reusing the > > slot we tried to find earlier. > > True, but I don't see an easy way to do that with PLDHash, and I don't > really have time at the moment to deal with that :/ That said this seems > preferable to the alternative of call twice manually, at least this way when > we have time to fix PLDHash we can get all the users for free. Yeah.
Flags: needinfo?(nfroyd)
![]() |
||
Comment 5•6 years ago
|
||
Alternatively, why not keep the API in nsBaseHashtable, but have it return a DataType&?
Assignee | ||
Comment 6•6 years ago
|
||
(In reply to Nathan Froyd [:froydnj] from comment #5) > Alternatively, why not keep the API in nsBaseHashtable, but have it return a > DataType&? yes, returning a reference to the actual type in memory makes a lot of sense ;)
Assignee | ||
Comment 7•6 years ago
|
||
This intends to expose basically the same functionality as operator[] on unordered_map.
Attachment #8811026 -
Flags: review?(nfroyd)
![]() |
||
Comment 8•6 years ago
|
||
Comment on attachment 8811026 [details] [diff] [review] add a GetOrInsert to nsbaseHashtable that returns a reference to the value Review of attachment 8811026 [details] [diff] [review]: ----------------------------------------------------------------- Please fix the commit message to correctly capitalize nsBaseHashtable. ::: xpcom/glue/nsBaseHashtable.h @@ +126,5 @@ > + return ent->mData; > + } > + > + ent = this->PutEntry(aKey); > + new(&ent->mData) UserDataType(); This seems unnecessary, as PutEntry() will have called EntryType::EntryType() on the entry already, which will have default-constructed |mData|. So I think this can be removed.
Attachment #8811026 -
Flags: review?(nfroyd) → feedback+
![]() |
||
Updated•6 years ago
|
Attachment #8808792 -
Attachment is obsolete: true
Assignee | ||
Comment 9•6 years ago
|
||
> ::: xpcom/glue/nsBaseHashtable.h
> @@ +126,5 @@
> > + return ent->mData;
> > + }
> > +
> > + ent = this->PutEntry(aKey);
> > + new(&ent->mData) UserDataType();
>
> This seems unnecessary, as PutEntry() will have called
> EntryType::EntryType() on the entry already, which will have
> default-constructed |mData|. So I think this can be removed.
yeah, I really should have caught that, sorry :(
Assignee | ||
Comment 10•6 years ago
|
||
This intends to expose basically the same functionality as operator[] on unordered_map.
Attachment #8811465 -
Flags: review?(nfroyd)
Assignee | ||
Updated•6 years ago
|
Attachment #8811026 -
Attachment is obsolete: true
![]() |
||
Updated•6 years ago
|
Attachment #8811465 -
Flags: review?(nfroyd) → review+
Comment 11•6 years ago
|
||
Pushed by tsaunders@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/0e27121698e4 add a GetOrInsert to nsBaseHashtable that returns a reference to the value r=froydnj
This (or bug 127-016) appears to have caused the a11y tests to fail like https://treeherder.mozilla.org/logviewer.html#?job_id=39326093&repo=mozilla-inbound Backed out in https://hg.mozilla.org/integration/mozilla-inbound/rev/b3b9d24cdb97
Flags: needinfo?(tbsaunde+mozbugs)
Comment 13•6 years ago
|
||
Backout by kwierso@gmail.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/c428116222e7 Backed out changeset 0e27121698e4 for a11y failures a=backout CLOSED TREE
Comment 14•6 years ago
|
||
Pushed by tsaunders@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/e943ad944554 add a GetOrInsert to nsBaseHashtable that returns a reference to the value r=froydnj
Comment 15•6 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/e943ad944554
Status: NEW → RESOLVED
Closed: 6 years ago
status-firefox53:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla53
Assignee | ||
Updated•6 years ago
|
Flags: needinfo?(tbsaunde+mozbugs)
Assignee | ||
Comment 16•6 years ago
|
||
Comment on attachment 8811465 [details] [diff] [review] add a GetOrInsert to nsBaseHashtable that returns a reference to the value dep of bug 1270916
Attachment #8811465 -
Flags: approval-mozilla-aurora?
Comment on attachment 8811465 [details] [diff] [review] add a GetOrInsert to nsBaseHashtable that returns a reference to the value OK for aurora, part of e10s/a11y uplift along with work from bug 1270916.
Attachment #8811465 -
Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
status-firefox52:
--- → affected
Updated•6 years ago
|
Assignee: nobody → tbsaunde+mozbugs
Comment 18•6 years ago
|
||
bugherderuplift |
https://hg.mozilla.org/releases/mozilla-aurora/rev/8fe631df8c66
You need to log in
before you can comment on or make changes to this bug.
Description
•