Commits
Dave Abrahams committed de368b90706
[stdlib] Make algorithms safe with illegal predicates Even if the user supplies an ordering predicate that isn't a strict-weak ordering, algorithms should not index beyond their bounds. Otherwise, a use of withUnsafeMutableStorage for optimization purposes could easily do an unsafe memory access. This commit comments and tests our algorithms that require strict weak orderings, and fixes safety problems in partition(). Most benchmarks are unaffected, but the rewrite of partition produces a 27% speedup in the Phonebook benchmark at -O3 and a 22% speedup at -Ofast. Also, at -Ofast, QuickSort lost 6% and RC4 gained 6%. These benchmarks were not noticeably affected at -O3 ====================`PrecommitBench_O3`==================== ````benchmark`,`baserun0`,`baserun1`,`baserun2`,``optrun0`,``optrun1`,``optrun2`,``delta`,`speedup` ````Phonebook`,``1608.00`,``1676.00`,``1651.00`,``1265.00`,``1278.00`,``1281.00`,`343.00`,```27.1%` ````QuickSort`,```430.00`,```448.00`,```429.00`,```428.00`,```431.00`,```428.00`,```1.00`,````0.2%` ``````````RC4`,```925.00`,```924.00`,```922.00`,```916.00`,```919.00`,```917.00`,```6.00`,````0.7%` ====================`PrecommitBench_Ofast`==================== ````benchmark`,`baserun0`,`baserun1`,`baserun2`,``optrun0`,``optrun1`,``optrun2`,``delta`,`speedup` ````Phonebook`,``1521.00`,``1546.00`,``1591.00`,``1252.00`,``1255.00`,``1256.00`,`269.00`,```21.5%` ````QuickSort`,```478.00`,```477.00`,```476.00`,```506.00`,```510.00`,```513.00`,``30.00`,```-5.9%` ``````````RC4`,``1033.00`,``1874.00`,``1030.00`,```974.00`,```982.00`,```975.00`,``56.00`,````5.7%` Swift SVN r20202