[libcxx-commits] [PATCH] D116296: [libc++] Add an early return for __partial_sort of an empty range.

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Dec 26 20:05:08 PST 2021


Quuxplusone created this revision.
Quuxplusone added reviewers: ldionne, hewillk, libc++, Mordante.
Quuxplusone added a project: libc++.
Quuxplusone requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added 1 blocking reviewer(s): libc++.

If `__first == __middle`, then `partial_sort` is a no-op; don't bother to iterate all the way from `__middle` to `__end`.

      

Fixes https://github.com/llvm/llvm-project/issues/49431


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116296

Files:
  libcxx/include/__algorithm/partial_sort.h


Index: libcxx/include/__algorithm/partial_sort.h
===================================================================
--- libcxx/include/__algorithm/partial_sort.h
+++ libcxx/include/__algorithm/partial_sort.h
@@ -33,6 +33,8 @@
 __partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
              _Compare __comp)
 {
+    if (__first == __middle)
+        return;
     _VSTD::__make_heap<_Compare>(__first, __middle, __comp);
     typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first;
     for (_RandomAccessIterator __i = __middle; __i != __last; ++__i)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116296.396259.patch
Type: text/x-patch
Size: 647 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211227/992552cd/attachment-0001.bin>


More information about the libcxx-commits mailing list