avm2: Also use avmplus' qsort in `Vector.sort`
This was forgotten in #17846.
This commit is contained in:
parent
24b0c8b01e
commit
e6e92dd175
|
@ -903,7 +903,9 @@ where
|
|||
/// will permute the slice arbitrarily, but won't return an error.
|
||||
///
|
||||
/// Original code: https://github.com/adobe/avmplus/blob/master/core/ArrayClass.cpp#L637
|
||||
fn qsort<T, E>(
|
||||
///
|
||||
/// NOTE: this is `pub(super)` so it can be called by `vector::sort`.
|
||||
pub(super) fn qsort<T, E>(
|
||||
slice: &mut [T],
|
||||
cmp: &mut impl FnMut(&T, &T) -> Result<Ordering, E>,
|
||||
) -> Result<(), E> {
|
||||
|
|
|
@ -764,6 +764,8 @@ pub fn slice<'gc>(
|
|||
}
|
||||
|
||||
/// Implements `Vector.sort`
|
||||
///
|
||||
/// TODO: Consider sharing this code with `globals::array::sort`?
|
||||
pub fn sort<'gc>(
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
this: Object<'gc>,
|
||||
|
@ -813,21 +815,18 @@ pub fn sort<'gc>(
|
|||
drop(vs);
|
||||
|
||||
let mut unique_sort_satisfied = true;
|
||||
let mut error_signal = Ok(());
|
||||
values.sort_unstable_by(|a, b| match compare(activation, *a, *b) {
|
||||
Ok(Ordering::Equal) => {
|
||||
super::array::qsort(&mut values, &mut |a, b| {
|
||||
compare(activation, *a, *b).map(|cmp| {
|
||||
if cmp == Ordering::Equal {
|
||||
unique_sort_satisfied = false;
|
||||
Ordering::Equal
|
||||
} else if options.contains(SortOptions::DESCENDING) {
|
||||
cmp.reverse()
|
||||
} else {
|
||||
cmp
|
||||
}
|
||||
Ok(v) if options.contains(SortOptions::DESCENDING) => v.reverse(),
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
error_signal = Err(e);
|
||||
Ordering::Less
|
||||
}
|
||||
});
|
||||
|
||||
error_signal?;
|
||||
})
|
||||
})?;
|
||||
|
||||
//NOTE: RETURNINDEXEDARRAY does NOT actually return anything useful.
|
||||
//The actual sorting still happens, but the results are discarded.
|
||||
|
|
Loading…
Reference in New Issue