Open Bug 1874892 Opened 2 years ago Updated 2 years ago

Set-Append function for nsTArray

Categories

(Core :: XPCOM, enhancement)

enhancement

Tracking

()

People

(Reporter: vhilla, Unassigned)

Details

During review of Bug 1830781, we wondered whether a function for set-append would make sense in nsTArray.

Some of these usages of if (!array.Contains(item) { array.AppendElement(item) } could be replaced with something like array.SetAppend(item).

Is nsTArray the right data structure in the first place? Would a hashmap work better?

I'm sorry, I should clarify that set refers to ordered set. Also see the note there:

Almost all cases on the web platform require an ordered set, instead of an unordered one, since interoperability requires that any developer-exposed enumeration of the set’s contents be consistent between browsers.

As described in the link, by "ordered set" what they really mean is a set where the iteration order is the order the elements were first inserted into the set. They should really call it an "insertion ordered set" or something, as normally I think somebody would assume the ordering would be based on the value of the elements.

You could use a set and an array. Only insert iterms in the array if they aren't in the set.

You need to log in before you can comment on or make changes to this bug.