Closed Bug 1691913 Opened 4 years ago Closed 4 years ago

Better align nsBaseHashtable::Get and nsBaseHashtable::GetOrInsert

Categories

(Core :: XPCOM, task)

task

Tracking

()

RESOLVED FIXED
88 Branch
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.

One option is to rename GetOrInsert to LookupOrInsert, which somehow fits in with existing Lookup* methods that also expose DataType&.

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).

Depends on: 1691894
Blocks: 1693306
Assignee: nobody → sgiesecke
Status: NEW → ASSIGNED

It should be called "Get" rather than "Lookup" because it returns
UserDataType. "Add" is called "Insert" in the other methods.

Depends on D105469

The functions should be called "Lookup" rather than "Get" because they return
a DataType& (rather than UserDataType).

Depends on D105471

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

Attachment #9203710 - Attachment description: Bug 1691913 - Fix forwarding of multiple constructor arguments to nsBaseHashtableET. r=#xpcom-reviewers → Bug 1691913 - Fix forwarding of constructor arguments to nsBaseHashtableET. r=#xpcom-reviewers
See Also: → 1374064
Keywords: leave-open
Pushed by sgiesecke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/a8f6d80352c4 Fix forwarding of constructor arguments to nsBaseHashtableET. r=xpcom-reviewers,nika https://hg.mozilla.org/integration/autoland/rev/c4e0b884258d Rename nsClassHashtable::LookupOrAdd to GetOrInsertNew. r=xpcom-reviewers,nika
Attachment #9203717 - Attachment description: Bug 1691913 - Add some convenience methods to LookupResult. r=#xpcom-reviewers → Bug 1691913 - Add some convenience methods to LookupResult and EntryHandle. r=#xpcom-reviewers
Attachment #9203715 - Attachment description: Bug 1691913 - Mark nsBaseHashtable (and its subclass') member functions nodiscard where appropriate. r=#xpcom-reviewers → Bug 1691913 - Mark nsBaseHashtable (and its subclasses') member functions nodiscard where appropriate. r=#xpcom-reviewers
Pushed by sgiesecke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f4b677bf05f6 Rename nsBaseHashtable::GetOrInsert(With) to LookupOrInsert(With). r=xpcom-reviewers,necko-reviewers,jgilbert,dragana,nika https://hg.mozilla.org/integration/autoland/rev/ff46eda9cc31 Rename nsBaseHashtable::Put to InsertOrUpdate. r=xpcom-reviewers,necko-reviewers,jgilbert,dragana,nika
Pushed by sgiesecke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/cf2c619858c1 Mark nsBaseHashtable (and its subclasses') member functions nodiscard where appropriate. r=xpcom-reviewers,necko-reviewers,dragana,nika
See Also: → 1695274
Pushed by sgiesecke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/4ea48ba52014 Add some convenience methods to LookupResult and EntryHandle. r=xpcom-reviewers,nika https://hg.mozilla.org/integration/autoland/rev/cff817b06e3e Remove uses of nsDataHashtable::GetValue. r=xpcom-reviewers,necko-reviewers,dragana,nika https://hg.mozilla.org/integration/autoland/rev/c503aa8bf0a1 Remove custom nsDataHashtable::GetValue. r=xpcom-reviewers,nika https://hg.mozilla.org/integration/autoland/rev/50804b10b092 Update documentation of nsBaseHashtable. r=xpcom-reviewers,nika
Keywords: leave-open
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: