File tree 2 files changed +17
-16
lines changed
2 files changed +17
-16
lines changed Original file line number Diff line number Diff line change @@ -903,7 +903,9 @@ where
903
903
/// will permute the slice arbitrarily, but won't return an error.
904
904
///
905
905
/// Original code: https://github.com/adobe/avmplus/blob/master/core/ArrayClass.cpp#L637
906
- fn qsort < T , E > (
906
+ ///
907
+ /// NOTE: this is `pub(super)` so it can be called by `vector::sort`.
908
+ pub ( super ) fn qsort < T , E > (
907
909
slice : & mut [ T ] ,
908
910
cmp : & mut impl FnMut ( & T , & T ) -> Result < Ordering , E > ,
909
911
) -> Result < ( ) , E > {
Original file line number Diff line number Diff line change @@ -764,6 +764,8 @@ pub fn slice<'gc>(
764
764
}
765
765
766
766
/// Implements `Vector.sort`
767
+ ///
768
+ /// TODO: Consider sharing this code with `globals::array::sort`?
767
769
pub fn sort < ' gc > (
768
770
activation : & mut Activation < ' _ , ' gc > ,
769
771
this : Object < ' gc > ,
@@ -813,21 +815,18 @@ pub fn sort<'gc>(
813
815
drop ( vs) ;
814
816
815
817
let mut unique_sort_satisfied = true ;
816
- let mut error_signal = Ok ( ( ) ) ;
817
- values. sort_unstable_by ( |a, b| match compare ( activation, * a, * b) {
818
- Ok ( Ordering :: Equal ) => {
819
- unique_sort_satisfied = false ;
820
- Ordering :: Equal
821
- }
822
- Ok ( v) if options. contains ( SortOptions :: DESCENDING ) => v. reverse ( ) ,
823
- Ok ( v) => v,
824
- Err ( e) => {
825
- error_signal = Err ( e) ;
826
- Ordering :: Less
827
- }
828
- } ) ;
829
-
830
- error_signal?;
818
+ super :: array:: qsort ( & mut values, & mut |a, b| {
819
+ compare ( activation, * a, * b) . map ( |cmp| {
820
+ if cmp == Ordering :: Equal {
821
+ unique_sort_satisfied = false ;
822
+ Ordering :: Equal
823
+ } else if options. contains ( SortOptions :: DESCENDING ) {
824
+ cmp. reverse ( )
825
+ } else {
826
+ cmp
827
+ }
828
+ } )
829
+ } ) ?;
831
830
832
831
//NOTE: RETURNINDEXEDARRAY does NOT actually return anything useful.
833
832
//The actual sorting still happens, but the results are discarded.
You can’t perform that action at this time.
0 commit comments