[libcxx-commits] [libcxx] [libc++] Improve the performance of std::make_heap a bit (PR #154092)

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Thu Sep 11 06:12:45 PDT 2025


mstorsjo wrote:

Hmm. I'm quite out of my depth here...

FWIW, I tried to see if this had been fixed in newer versions of Qt; the issue doesn't appear with Qt 6.9, but only with 6.8 (and probably earlier versions). The issue went away in https://github.com/qt/qtdeclarative/commit/6537b2b23b22d8ac776d1d97f436bb6d9e8e20da#diff-e2bfe467554d88bbaf4f85e0cd871919b55134a80767ed2812b6262bf0e7b520, where `std::sort(QSequentialIterable::RandomAccessIterator(iterable.mutableBegin()), QSequentialIterable::RandomAccessIterator(iterable.mutableEnd()), compare);` and `std::sort(QSequentialIterable::BidirectionalIterator(iterable.mutableBegin()), QSequentialIterable::BidirectionalIterator(iterable.mutableEnd()), compare);` were removed.



> Given that `make_heap` requires a random access iterator that part is not even optional.

Sorry, I don't really see where the user is invoking `make_heap` here - this is code invoking `std::sort`, which I presume does that somewhere under the hood.


> If its `iterator_category` derives from `random_access_iterator` it has to provide a subscript operator according to https://eel.is/c++draft/iterator.requirements#tab:randomaccessiterator.

I'm also hitting similar issues with the sorting with a bidirectional iterator (in the call `std::sort(QSequentialIterable::BidirectionalIterator(iterable.mutableBegin()), QSequentialIterable::BidirectionalIterator(iterable.mutableEnd()), compare);`):
```
/home/martin/clang-nightly/i686-w64-mingw32/include/c++/v1/__algorithm/sift_down.h:49:46: error: type 'QTaggedIterator<QTaggedIterator<QSequentialIterator, void>, std::bidirectional_iterator_tag>' does not provide a subscript operator
   49 |   } else if ((__child + 1) < __len && __comp(__first[__child], __first[__child + 1])) {
      |                                              ^~~~~~~ ~~~~~~~
```

https://github.com/llvm/llvm-project/pull/154092


More information about the libcxx-commits mailing list