[JS IR] stdlib: Use comparator in CharArray.sort

CharArray is represented as a regular JS Array. Its default sort order is based
on string representation of elements.
This commit is contained in:
Svyatoslav Kuzmich
2019-05-05 14:08:16 +03:00
parent 179acf0789
commit 362fbc8770
2 changed files with 8 additions and 2 deletions
@@ -1303,7 +1303,7 @@ public actual fun FloatArray.sort(): Unit {
* Sorts the array in-place.
*/
public actual fun CharArray.sort(): Unit {
this.asDynamic().sort()
this.asDynamic().sort(::primitiveCompareTo)
}
/**
@@ -1038,7 +1038,13 @@ object ArrayOps : TemplateGroupBase() {
body { "definedExternally" }
}
on(Backend.IR) {
body { "this.asDynamic().sort()" }
if (primitive == PrimitiveType.Char) {
// Requires comparator because default comparator of 'Array.prototype.sort' compares
// string representation of values
body { "this.asDynamic().sort(::primitiveCompareTo)" }
} else {
body { "this.asDynamic().sort()" }
}
}
} else {
body {