[libcxx-commits] [libcxx] f6fb7bf - [libc++] Add an early return for __partial_sort of an empty range.
Arthur O'Dwyer via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jan 4 13:15:44 PST 2022
Author: Arthur O'Dwyer
Date: 2022-01-04T16:14:05-05:00
New Revision: f6fb7bf636e3257a32a629460d447eea76616384
URL: https://github.com/llvm/llvm-project/commit/f6fb7bf636e3257a32a629460d447eea76616384
DIFF: https://github.com/llvm/llvm-project/commit/f6fb7bf636e3257a32a629460d447eea76616384.diff
LOG: [libc++] Add an early return for __partial_sort of an empty range.
If `__first == __middle`, then `partial_sort` is a no-op; don't
bother to iterate all the way from `__middle` to `__end`.
Fixes #49431.
Differential Revision: https://reviews.llvm.org/D116296
Added:
Modified:
libcxx/include/__algorithm/partial_sort.h
Removed:
################################################################################
diff --git a/libcxx/include/__algorithm/partial_sort.h b/libcxx/include/__algorithm/partial_sort.h
index 017ac90b67142..40e39e2be9741 100644
--- a/libcxx/include/__algorithm/partial_sort.h
+++ b/libcxx/include/__algorithm/partial_sort.h
@@ -33,6 +33,8 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 void
__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>::
diff erence_type __len = __middle - __first;
for (_RandomAccessIterator __i = __middle; __i != __last; ++__i)
More information about the libcxx-commits
mailing list