@@ -1511,34 +1511,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
1511
1511
1512
1512
// partition
1513
1513
1514
- // / This is a helper function...
1515
- // / Requires __len != 0 and !__pred(*__first),
1516
- // / same as __stable_partition_adaptive.
1517
- template <typename _ForwardIterator, typename _Predicate, typename _Distance>
1518
- _ForwardIterator
1519
- __inplace_stable_partition (_ForwardIterator __first,
1520
- _Predicate __pred, _Distance __len)
1521
- {
1522
- if (__len == 1 )
1523
- return __first;
1524
- _ForwardIterator __middle = __first;
1525
- std::advance (__middle, __len / 2 );
1526
- _ForwardIterator __left_split =
1527
- std::__inplace_stable_partition (__first, __pred, __len / 2 );
1528
- // Advance past true-predicate values to satisfy this
1529
- // function's preconditions.
1530
- _Distance __right_len = __len - __len / 2 ;
1531
- _ForwardIterator __right_split =
1532
- std::__find_if_not_n (__middle, __right_len, __pred);
1533
- if (__right_len)
1534
- __right_split = std::__inplace_stable_partition (__middle,
1535
- __pred,
1536
- __right_len);
1537
- std::rotate (__left_split, __middle, __right_split);
1538
- std::advance (__left_split, std::distance (__middle, __right_split));
1539
- return __left_split;
1540
- }
1541
-
1542
1514
// / This is a helper function...
1543
1515
// / Requires __first != __last and !__pred(__first)
1544
1516
// / and __len == distance(__first, __last).
@@ -1554,10 +1526,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
1554
1526
_Pointer __buffer,
1555
1527
_Distance __buffer_size)
1556
1528
{
1529
+ if (__len == 1 )
1530
+ return __first;
1531
+
1557
1532
if (__len <= __buffer_size)
1558
1533
{
1559
1534
_ForwardIterator __result1 = __first;
1560
1535
_Pointer __result2 = __buffer;
1536
+
1561
1537
// The precondition guarantees that !__pred(__first), so
1562
1538
// move that element to the buffer before starting the loop.
1563
1539
// This ensures that we only call __pred once per element.
@@ -1575,31 +1551,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
1575
1551
*__result2 = _GLIBCXX_MOVE (*__first);
1576
1552
++__result2;
1577
1553
}
1554
+
1578
1555
_GLIBCXX_MOVE3 (__buffer, __result2, __result1);
1579
1556
return __result1;
1580
1557
}
1581
- else
1582
- {
1583
- _ForwardIterator __middle = __first;
1584
- std::advance (__middle, __len / 2 );
1585
- _ForwardIterator __left_split =
1586
- std::__stable_partition_adaptive (__first, __middle, __pred,
1587
- __len / 2 , __buffer,
1588
- __buffer_size);
1589
- // Advance past true-predicate values to satisfy this
1590
- // function's preconditions.
1591
- _Distance __right_len = __len - __len / 2 ;
1592
- _ForwardIterator __right_split =
1593
- std::__find_if_not_n (__middle, __right_len, __pred);
1594
- if (__right_len)
1595
- __right_split =
1596
- std::__stable_partition_adaptive (__right_split, __last, __pred,
1597
- __right_len,
1598
- __buffer, __buffer_size);
1599
- std::rotate (__left_split, __middle, __right_split);
1600
- std::advance (__left_split, std::distance (__middle, __right_split));
1601
- return __left_split;
1602
- }
1558
+
1559
+ _ForwardIterator __middle = __first;
1560
+ std::advance (__middle, __len / 2 );
1561
+ _ForwardIterator __left_split =
1562
+ std::__stable_partition_adaptive (__first, __middle, __pred,
1563
+ __len / 2 , __buffer,
1564
+ __buffer_size);
1565
+
1566
+ // Advance past true-predicate values to satisfy this
1567
+ // function's preconditions.
1568
+ _Distance __right_len = __len - __len / 2 ;
1569
+ _ForwardIterator __right_split =
1570
+ std::__find_if_not_n (__middle, __right_len, __pred);
1571
+
1572
+ if (__right_len)
1573
+ __right_split =
1574
+ std::__stable_partition_adaptive (__right_split, __last, __pred,
1575
+ __right_len,
1576
+ __buffer, __buffer_size);
1577
+
1578
+ std::rotate (__left_split, __middle, __right_split);
1579
+ std::advance (__left_split, std::distance (__middle, __right_split));
1580
+ return __left_split;
1603
1581
}
1604
1582
1605
1583
template <typename _ForwardIterator, typename _Predicate>
@@ -1618,16 +1596,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
1618
1596
_DistanceType;
1619
1597
1620
1598
_Temporary_buffer<_ForwardIterator, _ValueType> __buf (__first, __last);
1621
- if (__buf.size () > 0 )
1622
- return
1623
- std::__stable_partition_adaptive (__first, __last, __pred,
1624
- _DistanceType (__buf.requested_size ()),
1625
- __buf.begin (),
1626
- _DistanceType (__buf.size ()));
1627
- else
1628
- return
1629
- std::__inplace_stable_partition (__first, __pred,
1630
- _DistanceType (__buf.requested_size ()));
1599
+ return
1600
+ std::__stable_partition_adaptive (__first, __last, __pred,
1601
+ _DistanceType (__buf.requested_size ()),
1602
+ __buf.begin (),
1603
+ _DistanceType (__buf.size ()));
1631
1604
}
1632
1605
1633
1606
/* *
@@ -2471,6 +2444,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
2471
2444
__gnu_cxx::__ops::__val_comp_iter (__comp));
2472
2445
__len11 = std::distance (__first, __first_cut);
2473
2446
}
2447
+
2474
2448
_BidirectionalIterator __new_middle
2475
2449
= std::__rotate_adaptive (__first_cut, __middle, __second_cut,
2476
2450
__len1 - __len11, __len22, __buffer,
@@ -2496,12 +2470,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
2496
2470
{
2497
2471
if (__len1 == 0 || __len2 == 0 )
2498
2472
return ;
2473
+
2499
2474
if (__len1 + __len2 == 2 )
2500
2475
{
2501
2476
if (__comp (__middle, __first))
2502
2477
std::iter_swap (__first, __middle);
2503
2478
return ;
2504
2479
}
2480
+
2505
2481
_BidirectionalIterator __first_cut = __first;
2506
2482
_BidirectionalIterator __second_cut = __middle;
2507
2483
_Distance __len11 = 0 ;
@@ -2524,6 +2500,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
2524
2500
__gnu_cxx::__ops::__val_comp_iter (__comp));
2525
2501
__len11 = std::distance (__first, __first_cut);
2526
2502
}
2503
+
2527
2504
std::rotate (__first_cut, __middle, __second_cut);
2528
2505
_BidirectionalIterator __new_middle = __first_cut;
2529
2506
std::advance (__new_middle, std::distance (__middle, __second_cut));
0 commit comments