nsTArray needs a stable sort algorithm (MergeSort)
Categories
(Core :: XPCOM, defect)
Tracking
()
Tracking | Status | |
---|---|---|
firefox80 | --- | fixed |
People
(Reporter: MatsPalmgren_bugz, Assigned: sg)
References
Details
Attachments
(1 file)
Reporter | ||
Comment 1•11 years ago
|
||
Reporter | ||
Comment 2•9 years ago
|
||
Comment 3•5 years ago
|
||
We have some std::stable_sort
usages in DOM, gfx, and layout. I feel it would be convenient if nsTArray has a stable-sort implementation.
Not sure comment 2 is still valid or not. I'd like to clear the severity flag to let this bug surface up. It would be great if xpcom hackers could comment on whether comment 1 is a feasible solution or not.
![]() |
||
Comment 4•5 years ago
|
||
(In reply to Ting-Yu Lin [:TYLin] (UTC-7) from comment #3)
We have some
std::stable_sort
usages in DOM, gfx, and layout. I feel it would be convenient if nsTArray has a stable-sort implementation.Not sure comment 2 is still valid or not. I'd like to clear the severity flag to let this bug surface up. It would be great if xpcom hackers could comment on whether comment 1 is a feasible solution or not.
I doubt comment 2 is still valid, given that we've updated our C++ standard library on Android several times since then. I'd take a patch for comment 1, I think.
Assignee | ||
Comment 5•5 years ago
|
||
Implementing comment 1 would be rather simple, but this doesn't really provide benefits over using std::stable_sort
using nsTArray's iterators. I guess it makes sense to provide operations as member functions of nsTArray
if they are more efficient, but that wouldn't be the case with this implementation. I don't think that cluttering the interface of nsTArray
with all kinds of algorithms is the right approach.
![]() |
||
Comment 6•5 years ago
|
||
(In reply to Simon Giesecke [:sg] [he/him] from comment #5)
Implementing comment 1 would be rather simple, but this doesn't really provide benefits over using
std::stable_sort
using nsTArray's iterators. I guess it makes sense to provide operations as member functions ofnsTArray
if they are more efficient, but that wouldn't be the case with this implementation. I don't think that cluttering the interface ofnsTArray
with all kinds of algorithms is the right approach.
I don't know if std::stable_sort
with nsTArray
's bounds checking would be all that great, but maybe the compiler can optimize away all the bounds checks. I think it'd be hard to deduce that all the accesses are within bounds, though.
Assignee | ||
Comment 7•5 years ago
|
||
Yes, probably you're right that a hand-crafted merge sort could be better at avoiding unnecessary bounds checks (also at using the memutils relocation optimization), but in comment 4 you said you'd accept take a patch "for comment 1", which suggested to just implement this using std::stable_sort
. Did you think this only as a starting point before changing that to a more optimized version?
![]() |
||
Comment 8•5 years ago
|
||
(In reply to Simon Giesecke [:sg] [he/him] from comment #7)
Yes, probably you're right that a hand-crafted merge sort could be better at avoiding unnecessary bounds checks (also at using the memutils relocation optimization), but in comment 4 you said you'd accept take a patch "for comment 1", which suggested to just implement this using
std::stable_sort
. Did you think this only as a starting point before changing that to a more optimized version?
I think you could make it:
void StableSort(const Comparator& aComp) {
std::stable_sort(Elements(), Elements() + Length(), aComp);
}
or so to at least avoid the bounds-checking.
Assignee | ||
Comment 9•5 years ago
|
||
(In reply to Nathan Froyd [:froydnj] from comment #8)
(In reply to Simon Giesecke [:sg] [he/him] from comment #7)
Yes, probably you're right that a hand-crafted merge sort could be better at avoiding unnecessary bounds checks (also at using the memutils relocation optimization), but in comment 4 you said you'd accept take a patch "for comment 1", which suggested to just implement this using
std::stable_sort
. Did you think this only as a starting point before changing that to a more optimized version?I think you could make it:
void StableSort(const Comparator& aComp) { std::stable_sort(Elements(), Elements() + Length(), aComp); }
or so to at least avoid the bounds-checking.
Ah yes, that's right... That's a good idea, and then probably worth adding the member function!
Assignee | ||
Comment 10•5 years ago
|
||
Updated•5 years ago
|
Comment 11•5 years ago
|
||
Comment 12•5 years ago
|
||
bugherder |
Description
•