Better align nsBaseHashtable::Get and nsBaseHashtable::GetOrInsert
Categories
(Core :: XPCOM, task)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox88 | --- | fixed |
People
(Reporter: sg, Assigned: sg)
References
Details
Attachments
(9 files)
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review |
nsBaseHashtable::Get returns UserDataType by value, while nsBaseHashtable::GetOrInsert returns a reference to the actual DataType& (and thus allows modifying the entry). This is very confusing, given that both member functions are called Get. Either of these should be renamed to use a different term than Get .
Probably a method that just returns a reference to the existing value should be added as well to avoid uses as in Bug 1691910 or in TelemetryOrigin::RecordOrigin, which should never add a new entry.
| Assignee | ||
Comment 1•5 years ago
|
||
One option is to rename GetOrInsert to LookupOrInsert, which somehow fits in with existing Lookup* methods that also expose DataType&.
| Assignee | ||
Comment 2•5 years ago
|
||
nsClassHashtable::LookupOrAdd should be renamed along as well, maybe to LookupOrInsertNew (it does the same as LookupOrInsert, but uses the arguments to construct an object on the heap).
| Assignee | ||
Comment 3•5 years ago
|
||
Depends on D105333
Updated•5 years ago
|
| Assignee | ||
Comment 4•5 years ago
|
||
It should be called "Get" rather than "Lookup" because it returns
UserDataType. "Add" is called "Insert" in the other methods.
Depends on D105469
| Assignee | ||
Comment 5•5 years ago
|
||
The functions should be called "Lookup" rather than "Get" because they return
a DataType& (rather than UserDataType).
Depends on D105471
| Assignee | ||
Comment 6•5 years ago
|
||
This makes the naming more consistent with other functions called
Insert and/or Update. Also, it removes the ambiguity whether
Put expects that an entry already exists or not, in particular because
it differed from nsTHashtable::PutEntry in that regard.
Depends on D105472
| Assignee | ||
Comment 7•5 years ago
|
||
Depends on D105473
| Assignee | ||
Comment 8•5 years ago
|
||
Depends on D105474
| Assignee | ||
Comment 9•5 years ago
|
||
Depends on D105475
| Assignee | ||
Comment 10•5 years ago
|
||
Depends on D105476
| Assignee | ||
Comment 11•5 years ago
|
||
Depends on D105477
Updated•5 years ago
|
| Assignee | ||
Updated•5 years ago
|
Comment 12•5 years ago
|
||
Comment 13•5 years ago
|
||
| bugherder | ||
Updated•5 years ago
|
Updated•5 years ago
|
Comment 14•5 years ago
|
||
Comment 15•5 years ago
|
||
Comment 16•5 years ago
|
||
| bugherder | ||
Comment 17•5 years ago
|
||
| Assignee | ||
Updated•5 years ago
|
Comment 18•5 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/4ea48ba52014
https://hg.mozilla.org/mozilla-central/rev/cff817b06e3e
https://hg.mozilla.org/mozilla-central/rev/c503aa8bf0a1
https://hg.mozilla.org/mozilla-central/rev/50804b10b092
Description
•