mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-18 09:21:35 +00:00
Implement <TypedArray>#sort and improve default comparator (#208)
This commit is contained in:
@ -32,6 +32,7 @@ export class Array<T> {
|
||||
);
|
||||
}
|
||||
|
||||
@inline
|
||||
get length(): i32 {
|
||||
return this.length_;
|
||||
}
|
||||
@ -324,12 +325,15 @@ export class Array<T> {
|
||||
|
||||
if (isReference<T>()) {
|
||||
// TODO replace this to faster stable sort (TimSort) when it implemented
|
||||
return changetype<this>(insertionSort<T>(this, comparator));
|
||||
insertionSort<T>(buffer, 0, length, comparator);
|
||||
return this;
|
||||
} else {
|
||||
return changetype<this>(length < 256
|
||||
? insertionSort<T>(this, comparator)
|
||||
: weakHeapSort<T>(this, comparator)
|
||||
);
|
||||
if (length < 256) {
|
||||
insertionSort<T>(buffer, 0, length, comparator);
|
||||
} else {
|
||||
weakHeapSort<T>(buffer, 0, length, comparator);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user