@nstudio/nativescript-compiler 9.2.0-alpha.17 → 9.2.0-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +3 -0
  2. package/config.js +1 -0
  3. package/dist/kotlin/access.js +8 -7
  4. package/dist/kotlin/arguments.js +6 -0
  5. package/dist/kotlin/assignment.js +22 -13
  6. package/dist/kotlin/builtins.js +67 -0
  7. package/dist/kotlin/calls.js +3 -2
  8. package/dist/kotlin/class-declaration.js +4 -9
  9. package/dist/kotlin/class-methods.js +2 -2
  10. package/dist/kotlin/core-api.js +1 -1
  11. package/dist/kotlin/declarations.js +1 -1
  12. package/dist/kotlin/expression-statements.js +13 -1
  13. package/dist/kotlin/functions.js +1 -0
  14. package/dist/kotlin/literals.js +4 -8
  15. package/dist/kotlin/names.js +4 -4
  16. package/dist/kotlin/native/api.js +1 -1
  17. package/dist/kotlin/operators.js +25 -25
  18. package/dist/kotlin/optional-chains.js +1 -1
  19. package/dist/kotlin/overrides.js +3 -3
  20. package/dist/kotlin/state-backend.js +6 -2
  21. package/dist/kotlin/translator.js +1 -1
  22. package/dist/kotlin/types.js +4 -4
  23. package/dist/semantics/classes.js +15 -0
  24. package/dist/semantics/conversion.js +9 -1
  25. package/dist/semantics/facts.js +1 -1
  26. package/dist/semantics/lang.js +10 -0
  27. package/dist/semantics/lower.js +54 -0
  28. package/dist/semantics/lowering-methods.js +5 -0
  29. package/dist/semantics/placement.js +9 -3
  30. package/dist/semantics/runtime.js +1 -0
  31. package/dist/semantics/signals.js +11 -0
  32. package/dist/semantics/states/missing.js +7 -0
  33. package/dist/semantics/tdz.js +54 -15
  34. package/dist/semantics/throws.js +2 -2
  35. package/dist/semantics/translator-methods.js +1 -1
  36. package/dist/swift/access.js +7 -9
  37. package/dist/swift/arguments.js +14 -9
  38. package/dist/swift/assignment.js +26 -15
  39. package/dist/swift/calls.js +13 -5
  40. package/dist/swift/class-methods.js +2 -1
  41. package/dist/swift/classes.js +7 -9
  42. package/dist/swift/components.js +3 -3
  43. package/dist/swift/control-flow.js +1 -1
  44. package/dist/swift/conversion.js +5 -2
  45. package/dist/swift/core-api.js +2 -2
  46. package/dist/swift/declarations.js +1 -1
  47. package/dist/swift/expressions.js +6 -2
  48. package/dist/swift/from-any.js +1 -1
  49. package/dist/swift/functions.js +5 -6
  50. package/dist/swift/global-calls.js +1 -1
  51. package/dist/swift/lenient.js +1 -6
  52. package/dist/swift/library.js +2 -2
  53. package/dist/swift/literals.js +8 -3
  54. package/dist/swift/method-values.js +2 -1
  55. package/dist/swift/modules.js +3 -3
  56. package/dist/swift/names.js +7 -7
  57. package/dist/swift/native/calls.js +10 -4
  58. package/dist/swift/object-classes.js +84 -1
  59. package/dist/swift/operators.js +31 -29
  60. package/dist/swift/placement.js +22 -6
  61. package/dist/swift/state-backend.js +3 -2
  62. package/dist/swift/static-calls.js +3 -4
  63. package/dist/swift/syntax.js +10 -6
  64. package/dist/swift/translator.js +1 -1
  65. package/dist/swift/type-facts.js +3 -3
  66. package/dist/swift/types.js +5 -5
  67. package/dist/targets/ios/build.js +1 -1
  68. package/kit-android/generated/kotlin/org/nativescript/kit/__Modules.kt +1 -0
  69. package/kit-android/generated/kotlin/org/nativescript/kit/__Objects.kt +525 -99
  70. package/kit-android/generated/kotlin/org/nativescript/kit/accessibility_accessibility_common.kt +2 -2
  71. package/kit-android/generated/kotlin/org/nativescript/kit/application_application_common.kt +29 -6
  72. package/kit-android/generated/kotlin/org/nativescript/kit/application_helpers_common.kt +14 -0
  73. package/kit-android/generated/kotlin/org/nativescript/kit/color_color_utils.kt +3 -3
  74. package/kit-android/generated/kotlin/org/nativescript/kit/css_mediaquery_index.kt +49 -1
  75. package/kit-android/generated/kotlin/org/nativescript/kit/data_observable_array_index.kt +0 -8
  76. package/kit-android/generated/kotlin/org/nativescript/kit/data_observable_index.kt +0 -16
  77. package/kit-android/generated/kotlin/org/nativescript/kit/data_virtual_array_index.kt +6 -4
  78. package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_index.kt +19 -7
  79. package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_internal_http_request_internal_common.kt +14 -0
  80. package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_internal_index.kt +19 -10
  81. package/kit-android/generated/kotlin/org/nativescript/kit/matrix_index.kt +17 -29
  82. package/kit-android/generated/kotlin/org/nativescript/kit/media_query_list_index.kt +144 -22
  83. package/kit-android/generated/kotlin/org/nativescript/kit/npm_css_what_src_parse.kt +8 -3
  84. package/kit-android/generated/kotlin/org/nativescript/kit/org.nativescript.NativeScriptLifecycleCallbacks.kt +2 -10
  85. package/kit-android/generated/kotlin/org/nativescript/kit/ui_builder_index.kt +0 -2
  86. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_bindable_expression_parser.kt +6 -10
  87. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_properties_index.kt +531 -8
  88. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_base_index.kt +0 -9
  89. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_weak_event_listener_index.kt +3 -3
  90. package/kit-android/generated/kotlin/org/nativescript/kit/ui_styling_style_index.kt +19 -0
  91. package/kit-android/generated/kotlin/org/nativescript/kit/ui_styling_style_properties.kt +5 -2
  92. package/kit-android/generated/kotlin/org/nativescript/kit/ui_styling_style_scope.kt +232 -174
  93. package/kit-android/generated/kotlin/org/nativescript/kit/ui_text_view_text_view_common.kt +1 -1
  94. package/kit-android/generated/kotlin/org/nativescript/kit/utils_android_runtime_version.kt +75 -0
  95. package/kit-android/generated/manifest.json +21 -18
  96. package/kit-android/generated/source-lines.json +1 -1
  97. package/kit-android/src/fromcore/kotlin/org/nativescript/kit/NativeScriptApplication.kt +9 -0
  98. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Array.kt +497 -42
  99. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Intl.kt +1 -1
  100. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/JSON.kt +22 -2
  101. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Strings.kt +32 -18
  102. package/kit-apple/Overlays/xml-free/Core/ui.builder.index.swift +7 -3
  103. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity1.swift +14 -10
  104. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity2.swift +3 -9
  105. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity3Plus.swift +20 -21
  106. package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_index_section_view_ios_android.swift +5 -7
  107. package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_ios_android_.swift +130 -0
  108. package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_oldIndex_newIndex.swift +2 -4
  109. package/kit-apple/Sources/NativeScriptKit/Core/Object_specified_substituted_reads.swift +115 -0
  110. package/kit-apple/Sources/NativeScriptKit/Core/Object_substituted_values_reads.swift +113 -0
  111. package/kit-apple/Sources/NativeScriptKit/Core/Object_substituted_values_reads_.swift +113 -0
  112. package/kit-apple/Sources/NativeScriptKit/Core/application.application-common.swift +348 -330
  113. package/kit-apple/Sources/NativeScriptKit/Core/application.application.ios.swift +358 -359
  114. package/kit-apple/Sources/NativeScriptKit/Core/application.helpers-common.swift +47 -29
  115. package/kit-apple/Sources/NativeScriptKit/Core/connectivity.index.ios.swift +3 -1
  116. package/kit-apple/Sources/NativeScriptKit/Core/css-mediaquery.index.swift +95 -53
  117. package/kit-apple/Sources/NativeScriptKit/Core/css.CSS3Parser.swift +1 -1
  118. package/kit-apple/Sources/NativeScriptKit/Core/css.parser.swift +1 -1
  119. package/kit-apple/Sources/NativeScriptKit/Core/data.observable-array.index.swift +3 -3
  120. package/kit-apple/Sources/NativeScriptKit/Core/file-system.file-system-access.ios.swift +58 -49
  121. package/kit-apple/Sources/NativeScriptKit/Core/file-system.index.swift +10 -10
  122. package/kit-apple/Sources/NativeScriptKit/Core/http.http-request-internal.http-request-internal-common.swift +18 -0
  123. package/kit-apple/Sources/NativeScriptKit/Core/http.http-request-internal.index.ios.swift +67 -52
  124. package/kit-apple/Sources/NativeScriptKit/Core/http.index.swift +3 -3
  125. package/kit-apple/Sources/NativeScriptKit/Core/image-source.index.ios.swift +69 -53
  126. package/kit-apple/Sources/NativeScriptKit/Core/js-libs.easysax.easysax.swift +4 -22
  127. package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +144 -32
  128. package/kit-apple/Sources/NativeScriptKit/Core/manifest.json +30 -19
  129. package/kit-apple/Sources/NativeScriptKit/Core/media-query-list.index.swift +190 -78
  130. package/kit-apple/Sources/NativeScriptKit/Core/native-window.native-window.ios.swift +1 -1
  131. package/kit-apple/Sources/NativeScriptKit/Core/npm.css-what.src.parse.swift +205 -201
  132. package/kit-apple/Sources/NativeScriptKit/Core/npm.css-what.src.stringify.swift +41 -42
  133. package/kit-apple/Sources/NativeScriptKit/Core/npm.css-what.src.types.swift +1 -1
  134. package/kit-apple/Sources/NativeScriptKit/Core/trace.index.swift +2 -2
  135. package/kit-apple/Sources/NativeScriptKit/Core/ui.action-bar.index.ios.swift +33 -21
  136. package/kit-apple/Sources/NativeScriptKit/Core/ui.activity-indicator.index.ios.swift +12 -6
  137. package/kit-apple/Sources/NativeScriptKit/Core/ui.animation.index.ios.swift +77 -65
  138. package/kit-apple/Sources/NativeScriptKit/Core/ui.animation.keyframe-animation.swift +1 -1
  139. package/kit-apple/Sources/NativeScriptKit/Core/ui.builder.index.swift +10 -6
  140. package/kit-apple/Sources/NativeScriptKit/Core/ui.button.index.ios.swift +14 -13
  141. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.properties.index.swift +1273 -824
  142. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view-base.index.swift +2 -2
  143. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.index.ios.swift +87 -67
  144. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.view-common.swift +1 -1
  145. package/kit-apple/Sources/NativeScriptKit/Core/ui.date-picker.index.ios.swift +17 -16
  146. package/kit-apple/Sources/NativeScriptKit/Core/ui.dialogs.index.ios.swift +2 -2
  147. package/kit-apple/Sources/NativeScriptKit/Core/ui.editable-text-base.index.ios.swift +27 -18
  148. package/kit-apple/Sources/NativeScriptKit/Core/ui.frame.frame-common.swift +2 -1
  149. package/kit-apple/Sources/NativeScriptKit/Core/ui.frame.index.ios.swift +6 -6
  150. package/kit-apple/Sources/NativeScriptKit/Core/ui.html-view.index.ios.swift +9 -9
  151. package/kit-apple/Sources/NativeScriptKit/Core/ui.image.index.ios.swift +6 -6
  152. package/kit-apple/Sources/NativeScriptKit/Core/ui.label.index.ios.swift +8 -8
  153. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.flexbox-layout.index.ios.swift +22 -21
  154. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.layout-base.ios.swift +4 -3
  155. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.liquid-glass-container.index.ios.swift +1 -1
  156. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.liquid-glass.index.ios.swift +1 -1
  157. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.root-layout.index.ios.swift +2 -2
  158. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.root-layout.root-layout-common.swift +9 -9
  159. package/kit-apple/Sources/NativeScriptKit/Core/ui.list-picker.index.ios.swift +9 -6
  160. package/kit-apple/Sources/NativeScriptKit/Core/ui.list-view.index.ios.swift +38 -20
  161. package/kit-apple/Sources/NativeScriptKit/Core/ui.page.index.ios.swift +204 -190
  162. package/kit-apple/Sources/NativeScriptKit/Core/ui.progress.index.ios.swift +12 -10
  163. package/kit-apple/Sources/NativeScriptKit/Core/ui.repeater.index.swift +2 -6
  164. package/kit-apple/Sources/NativeScriptKit/Core/ui.scroll-view.index.ios.swift +18 -9
  165. package/kit-apple/Sources/NativeScriptKit/Core/ui.search-bar.index.ios.swift +28 -18
  166. package/kit-apple/Sources/NativeScriptKit/Core/ui.segmented-bar.index.ios.swift +19 -12
  167. package/kit-apple/Sources/NativeScriptKit/Core/ui.slider.index.ios.swift +14 -12
  168. package/kit-apple/Sources/NativeScriptKit/Core/ui.split-view.index.ios.swift +17 -12
  169. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.background.ios.swift +2 -2
  170. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.clip-path-function.swift +1 -1
  171. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.css-animation-parser.swift +1 -1
  172. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.css-selector.swift +2 -2
  173. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.font-common.swift +2 -2
  174. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.style-scope.swift +869 -838
  175. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.style.index.swift +46 -31
  176. package/kit-apple/Sources/NativeScriptKit/Core/ui.switch.index.ios.swift +12 -10
  177. package/kit-apple/Sources/NativeScriptKit/Core/ui.tab-view.index.ios.swift +36 -20
  178. package/kit-apple/Sources/NativeScriptKit/Core/ui.text-base.formatted-string.swift +3 -4
  179. package/kit-apple/Sources/NativeScriptKit/Core/ui.text-base.index.ios.swift +25 -22
  180. package/kit-apple/Sources/NativeScriptKit/Core/ui.text-base.text-base-common.swift +2 -3
  181. package/kit-apple/Sources/NativeScriptKit/Core/ui.text-field.index.ios.swift +21 -14
  182. package/kit-apple/Sources/NativeScriptKit/Core/ui.text-view.index.ios.swift +33 -21
  183. package/kit-apple/Sources/NativeScriptKit/Core/ui.text-view.text-view-common.swift +1 -1
  184. package/kit-apple/Sources/NativeScriptKit/Core/ui.time-picker.index.ios.swift +22 -18
  185. package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.index.ios.swift +2 -2
  186. package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.modal-transition.ios.swift +4 -4
  187. package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.page-transition.ios.swift +2 -2
  188. package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.shared-transition-helper.ios.swift +32 -32
  189. package/kit-apple/Sources/NativeScriptKit/Core/ui.web-view.index.ios.swift +1 -1
  190. package/kit-apple/Sources/NativeScriptKit/Core/ui.web-view.web-view-common.swift +2 -2
  191. package/kit-apple/Sources/NativeScriptKit/Core/utils.android-runtime-version.swift +77 -0
  192. package/kit-apple/Sources/NativeScriptKit/Core/utils.debug-source.swift +2 -2
  193. package/kit-apple/Sources/NativeScriptKit/Core/utils.index.ios.swift +2 -2
  194. package/kit-apple/Sources/NativeScriptKit/Core/xhr.index.swift +62 -61
  195. package/kit-apple/Sources/NativeScriptKit/Runtime/Array.swift +4 -0
  196. package/kit-apple/Sources/NativeScriptKit/Runtime/Dynamic.swift +2 -0
  197. package/kit-apple/Sources/NativeScriptKit/Runtime/Interop.swift +1 -1
  198. package/kit-apple/Sources/NativeScriptKit/Runtime/Intl.swift +1 -1
  199. package/kit-apple/Sources/NativeScriptKit/Runtime/Iterators.swift +1 -1
  200. package/kit-apple/Sources/NativeScriptKit/Runtime/JSON.swift +280 -9
  201. package/kit-apple/Sources/NativeScriptKit/Runtime/Lowering.swift +3 -2
  202. package/kit-apple/Sources/NativeScriptKit/Runtime/Native.swift +2 -1
  203. package/kit-apple/Sources/NativeScriptKit/Runtime/Prototypes.swift +1 -0
  204. package/kit-apple/Sources/NativeScriptKit/Runtime/Symbol.swift +1 -0
  205. package/kit-apple/Sources/NativeScriptKit/Runtime/Values.swift +1 -0
  206. package/kit-apple/Sources/NativeScriptKit/Runtime/Views.swift +2 -0
  207. package/package.json +6 -4
@@ -1,22 +1,63 @@
1
1
  package org.nativescript.kit
2
2
 
3
+ private val EMPTY_ARRAY_STORAGE = ArrayList<Any?>(0)
4
+
3
5
  /**
4
6
  * A JavaScript array: reference semantics, JavaScript method names, `Double` indexes and lengths.
5
7
  * Reading past the end is undefined through `element`, which translated code uses for `a[i]`.
6
8
  */
7
9
  open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertible {
8
- var storage: ArrayList<T> = storage
9
- internal set
10
+ @PublishedApi internal var _storage: ArrayList<T>? = storage
11
+ @PublishedApi internal var doubles: DoubleArray? = null
12
+ @PublishedApi internal var dSize: Int = 0
13
+
14
+ var storage: ArrayList<T>
15
+ get() {
16
+ val d = doubles
17
+ if (d != null) return materializeDoubles(d)
18
+ return _storage!!
19
+ }
20
+ internal set(value) {
21
+ doubles = null
22
+ dSize = 0
23
+ _storage = value
24
+ }
10
25
  var jsTracker: JSTracker? = null
11
26
 
12
27
  constructor() : this(ArrayList())
13
28
  constructor(items: Collection<T>) : this(ArrayList(items))
14
29
 
30
+ @Suppress("UNCHECKED_CAST")
31
+ @PublishedApi internal fun materializeDoubles(d: DoubleArray): ArrayList<T> {
32
+ val n = dSize
33
+ val list = ArrayList<T>(n)
34
+ var i = 0
35
+ while (i < n) { list.add(d[i] as T); i++ }
36
+ _storage = list
37
+ doubles = null
38
+ dSize = 0
39
+ return list
40
+ }
41
+
42
+ @PublishedApi internal fun appendDouble(v: Double) {
43
+ var d = doubles!!
44
+ val n = dSize
45
+ if (n == d.size) {
46
+ d = d.copyOf(if (n == 0) 8 else n shl 1)
47
+ doubles = d
48
+ }
49
+ d[n] = v
50
+ dSize = n + 1
51
+ }
52
+
15
53
  private fun track() { jsTracker?.track() }
16
54
  private fun trigger() { jsTracker?.trigger() }
17
55
 
18
- private fun read(i: Int): T {
19
- val v = storage[i]
56
+ @Suppress("UNCHECKED_CAST")
57
+ @PublishedApi internal fun read(i: Int): T {
58
+ val d = doubles
59
+ if (d != null) return d[i] as T
60
+ val v = _storage!![i]
20
61
  if (jsTracker != null) jsReactiveAny(v)
21
62
  return v
22
63
  }
@@ -24,19 +65,20 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
24
65
  // Elements
25
66
 
26
67
  val size: Int
27
- get() { track(); return storage.size }
68
+ get() { track(); return if (doubles != null) dSize else _storage!!.size }
28
69
 
29
70
  /** The elements as a list, read through the tracker. */
30
71
  val elements: List<T>
31
72
  get() {
32
73
  track()
33
- if (jsTracker != null) storage.forEach { jsReactiveAny(it) }
34
- return storage
74
+ val list = storage
75
+ if (jsTracker != null) list.forEach { jsReactiveAny(it) }
76
+ return list
35
77
  }
36
78
 
37
79
  /** `array.length`. Setting it shorter truncates; longer adds holes. */
38
80
  var length: Double
39
- get() { track(); return storage.size.toDouble() }
81
+ get() { track(); return (if (doubles != null) dSize else _storage!!.size).toDouble() }
40
82
  set(value) {
41
83
  if (value < 0 || value > 4_294_967_295.0 || value != Math.floor(value)) throw JSException(JSRangeError("Invalid array length"))
42
84
  setLength(value.toInt())
@@ -44,13 +86,18 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
44
86
 
45
87
  @Suppress("UNCHECKED_CAST")
46
88
  internal fun setLength(n: Int) {
47
- if (n < storage.size) {
48
- while (storage.size > n) storage.removeAt(storage.size - 1)
89
+ if (doubles != null) {
90
+ if (n < dSize) { dSize = n; return }
91
+ if (n == dSize) return
92
+ }
93
+ val list = storage
94
+ if (n < list.size) {
95
+ while (list.size > n) list.removeAt(list.size - 1)
49
96
  jsHoles?.clear(n, Int.MAX_VALUE)
50
97
  trigger()
51
- } else if (n > storage.size) {
52
- (jsHoles ?: java.util.BitSet().also { jsHoles = it }).set(storage.size, n)
53
- while (storage.size < n) storage.add(null as T)
98
+ } else if (n > list.size) {
99
+ (jsHoles ?: java.util.BitSet().also { jsHoles = it }).set(list.size, n)
100
+ while (list.size < n) list.add(null as T)
54
101
  trigger()
55
102
  }
56
103
  }
@@ -61,22 +108,35 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
61
108
  /** `a[i]` as JavaScript reads it: undefined unless `i` is an integer index in range, or a key the array was given. */
62
109
  @Suppress("UNCHECKED_CAST")
63
110
  fun element(i: Double): T? {
111
+ val d = doubles
112
+ if (d != null) {
113
+ val k = i.toInt()
114
+ if (k >= 0 && k.toDouble() == i) return if (k < dSize) d[k] as T else null
115
+ if (i != Math.floor(i) || i < 0 || i >= 4_294_967_295.0) return jsProperties?.get(jsNumberToString(i), this) as T?
116
+ return null
117
+ }
64
118
  track()
119
+ val list = _storage!!
65
120
  val k = i.toInt()
66
- if (k >= 0 && k.toDouble() == i) return if (k < storage.size) read(k) else null
121
+ if (k >= 0 && k.toDouble() == i) return if (k < list.size) read(k) else null
67
122
  if (i != Math.floor(i) || i < 0 || i >= 4_294_967_295.0) return jsProperties?.get(jsNumberToString(i), this) as T?
68
- if (i >= storage.size) return null
123
+ if (i >= list.size) return null
69
124
  return read(i.toInt())
70
125
  }
71
126
 
72
127
  private fun readTracked(i: Int): T {
73
128
  jsTracker!!.track()
74
- val v = storage[i]
129
+ val v = _storage!![i]
75
130
  jsReactiveAny(v)
76
131
  return v
77
132
  }
78
133
 
79
- operator fun get(i: Int): T = if (jsTracker == null) storage[i] else readTracked(i)
134
+ @Suppress("UNCHECKED_CAST")
135
+ operator fun get(i: Int): T {
136
+ val d = doubles
137
+ if (d != null) return d[i] as T
138
+ return if (jsTracker == null) _storage!![i] else readTracked(i)
139
+ }
80
140
 
81
141
  operator fun get(i: Double): T = get(i.toInt())
82
142
 
@@ -85,21 +145,33 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
85
145
 
86
146
  @Suppress("UNCHECKED_CAST")
87
147
  operator fun set(i: Int, value: T) {
148
+ val d = doubles
149
+ if (d != null && value is Double) {
150
+ if (i >= 0 && i < dSize) { d[i] = value; return }
151
+ if (i == dSize) { appendDouble(value); return }
152
+ }
153
+ val list = storage
88
154
  when {
89
- i < storage.size -> { storage[i] = value; jsHoles?.clear(i) }
155
+ i < list.size -> { list[i] = value; jsHoles?.clear(i) }
90
156
  else -> {
91
- if (storage.size < i) (jsHoles ?: java.util.BitSet().also { jsHoles = it }).set(storage.size, i)
92
- while (storage.size < i) storage.add(null as T)
93
- storage.add(value)
157
+ if (list.size < i) (jsHoles ?: java.util.BitSet().also { jsHoles = it }).set(list.size, i)
158
+ while (list.size < i) list.add(null as T)
159
+ list.add(value)
94
160
  }
95
161
  }
96
162
  trigger()
97
163
  }
98
164
 
99
165
  operator fun set(i: Double, value: T) {
166
+ val d = doubles
100
167
  val k = i.toInt()
101
- if (k >= 0 && k.toDouble() == i && k < storage.size) {
102
- storage[k] = value
168
+ if (d != null && value is Double && k >= 0 && k.toDouble() == i) {
169
+ if (k < dSize) { d[k] = value; return }
170
+ if (k == dSize) { appendDouble(value); return }
171
+ }
172
+ val list = storage
173
+ if (k >= 0 && k.toDouble() == i && k < list.size) {
174
+ list[k] = value
103
175
  jsHoles?.clear(k)
104
176
  trigger()
105
177
  return
@@ -133,6 +205,13 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
133
205
  }
134
206
 
135
207
  fun at(i: Double): T? {
208
+ val d = doubles
209
+ if (d != null) {
210
+ var k = jsToIntegerOrInfinity(i)
211
+ if (k < 0) k += dSize
212
+ @Suppress("UNCHECKED_CAST")
213
+ return if (k >= 0 && k < dSize) d[k.toInt()] as T else null
214
+ }
136
215
  track()
137
216
  var k = jsToIntegerOrInfinity(i)
138
217
  if (k < 0) k += storage.size
@@ -142,7 +221,12 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
142
221
  override fun iterator(): Iterator<T> {
143
222
  var i = 0
144
223
  return object : Iterator<T> {
145
- override fun hasNext(): Boolean { track(); return i < storage.size }
224
+ override fun hasNext(): Boolean {
225
+ val d = doubles
226
+ if (d != null) return i < dSize
227
+ track()
228
+ return i < _storage!!.size
229
+ }
146
230
  override fun next(): T = read(i++)
147
231
  }
148
232
  }
@@ -165,16 +249,28 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
165
249
  // Mutation
166
250
 
167
251
  fun push(item: T): Double {
168
- storage.add(item)
252
+ val d = doubles
253
+ if (d != null && item is Double) {
254
+ appendDouble(item)
255
+ return dSize.toDouble()
256
+ }
257
+ val list = storage
258
+ list.add(item)
169
259
  trigger()
170
- return storage.size.toDouble()
260
+ return list.size.toDouble()
171
261
  }
172
262
 
173
263
  fun push(vararg items: T): Double {
174
- storage.ensureCapacity(storage.size + items.size)
175
- for (item in items) storage.add(item)
264
+ val d = doubles
265
+ if (d != null && items.all { it is Double }) {
266
+ for (item in items) appendDouble(item as Double)
267
+ return dSize.toDouble()
268
+ }
269
+ val list = storage
270
+ list.ensureCapacity(list.size + items.size)
271
+ for (item in items) list.add(item)
176
272
  trigger()
177
- return storage.size.toDouble()
273
+ return list.size.toDouble()
178
274
  }
179
275
 
180
276
  /** `a.push(...items)`. */
@@ -184,9 +280,16 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
184
280
  return storage.size.toDouble()
185
281
  }
186
282
 
283
+ @Suppress("UNCHECKED_CAST")
187
284
  fun pop(): T? {
188
- if (storage.isEmpty()) return null
189
- val v = storage.removeAt(storage.size - 1)
285
+ val d = doubles
286
+ if (d != null) {
287
+ if (dSize == 0) return null
288
+ return d[--dSize] as T
289
+ }
290
+ val list = storage
291
+ if (list.isEmpty()) return null
292
+ val v = list.removeAt(list.size - 1)
190
293
  trigger()
191
294
  return v
192
295
  }
@@ -227,6 +330,19 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
227
330
  }
228
331
 
229
332
  fun reverse(): JSArray<T> {
333
+ val d = doubles
334
+ if (d != null) {
335
+ var lo = 0
336
+ var hi = dSize - 1
337
+ while (lo < hi) {
338
+ val tmp = d[lo]
339
+ d[lo] = d[hi]
340
+ d[hi] = tmp
341
+ lo++
342
+ hi--
343
+ }
344
+ return this
345
+ }
230
346
  storage.reverse()
231
347
  trigger()
232
348
  return this
@@ -283,22 +399,40 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
283
399
  }
284
400
 
285
401
  fun fill(value: T, start: Double = 0.0, end: Double? = null): JSArray<T> {
286
- val n = storage.size
402
+ val d = doubles
403
+ if (d != null && value is Double) {
404
+ val n = dSize
405
+ val s = jsRelativeIndex(start, n)
406
+ val e = if (end == null) n else jsRelativeIndex(end, n)
407
+ if (s < e) java.util.Arrays.fill(d, s, e, value)
408
+ return this
409
+ }
410
+ val list = storage
411
+ val n = list.size
287
412
  val s = jsRelativeIndex(start, n)
288
413
  val e = if (end == null) n else jsRelativeIndex(end, n)
289
- for (i in s until e) storage[i] = value
414
+ for (i in s until e) list[i] = value
290
415
  trigger()
291
416
  return this
292
417
  }
293
418
 
294
419
  // Copies and searches
295
420
 
421
+ @Suppress("UNCHECKED_CAST")
296
422
  fun slice(start: Double = 0.0, end: Double? = null): JSArray<T> {
423
+ val d = doubles
424
+ if (d != null) {
425
+ val n = dSize
426
+ val s = jsRelativeIndex(start, n)
427
+ val e = if (end == null) n else jsRelativeIndex(end, n)
428
+ return (if (s < e) ofDoubles(d.copyOfRange(s, e), e - s) else ofDoubles(DoubleArray(0), 0)) as JSArray<T>
429
+ }
297
430
  track()
298
- val n = storage.size
431
+ val list = storage
432
+ val n = list.size
299
433
  val s = jsRelativeIndex(start, n)
300
434
  val e = if (end == null) n else jsRelativeIndex(end, n)
301
- return if (s < e) JSArray(ArrayList(storage.subList(s, e))) else JSArray()
435
+ return if (s < e) JSArray(ArrayList(list.subList(s, e))) else JSArray()
302
436
  }
303
437
 
304
438
  /** `array.concat(...items)`: an item that is an array adds its elements. */
@@ -427,7 +561,7 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
427
561
  return true
428
562
  }
429
563
 
430
- fun forEach(f: (T) -> Unit) {
564
+ inline fun forEach(f: (T) -> Unit) {
431
565
  val list = storage
432
566
  val n = size
433
567
  var i = 0
@@ -438,7 +572,7 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
438
572
  }
439
573
  }
440
574
 
441
- fun forEach(f: (T, Double) -> Unit) {
575
+ inline fun forEach(f: (T, Double) -> Unit) {
442
576
  val list = storage
443
577
  val n = size
444
578
  var i = 0
@@ -456,7 +590,7 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
456
590
  while (i < n && i < list.size) { f(read(i), i.toDouble(), this); i++ }
457
591
  }
458
592
 
459
- fun <U> map(f: (T) -> U): JSArray<U> {
593
+ inline fun <U> map(f: (T) -> U): JSArray<U> {
460
594
  val list = storage
461
595
  val n = size
462
596
  val out = ArrayList<U>(n)
@@ -469,7 +603,7 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
469
603
  return JSArray(out)
470
604
  }
471
605
 
472
- fun <U> map(f: (T, Double) -> U): JSArray<U> {
606
+ inline fun <U> map(f: (T, Double) -> U): JSArray<U> {
473
607
  val list = storage
474
608
  val n = size
475
609
  val out = ArrayList<U>(n)
@@ -491,7 +625,7 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
491
625
  return JSArray(out)
492
626
  }
493
627
 
494
- fun filter(f: (T) -> Boolean): JSArray<T> {
628
+ inline fun filter(f: (T) -> Boolean): JSArray<T> {
495
629
  val list = storage
496
630
  val n = size
497
631
  val out = ArrayList<T>()
@@ -504,7 +638,7 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
504
638
  return JSArray(out)
505
639
  }
506
640
 
507
- fun filter(f: (T, Double) -> Boolean): JSArray<T> {
641
+ inline fun filter(f: (T, Double) -> Boolean): JSArray<T> {
508
642
  val list = storage
509
643
  val n = size
510
644
  val out = ArrayList<T>()
@@ -541,7 +675,7 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
541
675
  return JSArray(out)
542
676
  }
543
677
 
544
- fun <U> reduce(f: (U, T) -> U, initial: U): U {
678
+ inline fun <U> reduce(f: (U, T) -> U, initial: U): U {
545
679
  var acc = initial
546
680
  val list = storage
547
681
  val n = size
@@ -645,12 +779,32 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
645
779
  }
646
780
 
647
781
  override fun jsMakeReactive() {
782
+ val d = doubles
783
+ if (d != null) materializeDoubles(d)
648
784
  if (jsTracker == null) jsTracker = JSTracker()
649
785
  }
650
786
 
651
787
  override fun toString(): String = jsInspect(this)
652
788
 
653
789
  companion object {
790
+ @Suppress("UNCHECKED_CAST")
791
+ @PublishedApi internal fun ofDoubles(data: DoubleArray, count: Int): JSArray<Double> {
792
+ val a = JSArray<Double>(EMPTY_ARRAY_STORAGE as ArrayList<Double>)
793
+ a._storage = null
794
+ a.doubles = data
795
+ a.dSize = count
796
+ return a
797
+ }
798
+
799
+ fun doubles(): JSArray<Double> = ofDoubles(DoubleArray(0), 0)
800
+ fun doublesOf(vararg items: Double): JSArray<Double> = ofDoubles(items, items.size)
801
+ fun doublesFilled(length: Double, value: Double): JSArray<Double> {
802
+ val n = length.toInt()
803
+ val data = DoubleArray(n)
804
+ if (value != 0.0) java.util.Arrays.fill(data, value)
805
+ return ofDoubles(data, n)
806
+ }
807
+
654
808
  fun <T> of(vararg items: T): JSArray<T> = JSArray(items.toList())
655
809
  fun <T> from(items: Iterable<T>): JSArray<T> = JSArray(ArrayList(items.toList()))
656
810
  fun <T> from(items: Iterable<T>, f: (T, Double) -> T): JSArray<T> = JSArray(ArrayList(items.mapIndexed { i, v -> f(v, i.toDouble()) }))
@@ -659,6 +813,307 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
659
813
  }
660
814
  }
661
815
 
816
+ /** Unboxed numeric element read (`a[i]` as `Double`): `NaN` past the end, matching `(element(i) ?: Double.NaN)`. */
817
+ fun JSArray<Double>.numberAt(i: Double): Double {
818
+ val d = doubles
819
+ val k = i.toInt()
820
+ if (d != null && k >= 0 && k < dSize && k.toDouble() == i) return d[k]
821
+ return element(i) ?: Double.NaN
822
+ }
823
+
824
+ /** Unboxed numeric element write (`a[i] = v`). */
825
+ fun JSArray<Double>.setDouble(i: Double, value: Double) {
826
+ val d = doubles
827
+ val k = i.toInt()
828
+ if (d != null && k >= 0 && k.toDouble() == i) {
829
+ if (k < dSize) { d[k] = value; return }
830
+ if (k == dSize) { appendDouble(value); return }
831
+ }
832
+ set(i, value)
833
+ }
834
+
835
+ /** Unboxed numeric compound addition (`a[i] += delta`). */
836
+ fun JSArray<Double>.addDoubleAt(i: Double, delta: Double) {
837
+ val d = doubles
838
+ val k = i.toInt()
839
+ if (d != null && k >= 0 && k < dSize && k.toDouble() == i) {
840
+ d[k] += delta
841
+ return
842
+ }
843
+ set(i, (element(i) ?: Double.NaN) + delta)
844
+ }
845
+
846
+ /** Unboxed single-element push onto a numeric array. */
847
+ fun JSArray<Double>.pushDouble(value: Double): Double {
848
+ if (doubles != null) {
849
+ appendDouble(value)
850
+ return dSize.toDouble()
851
+ }
852
+ return push(value)
853
+ }
854
+
855
+ /** Unboxed `number[].map((x) => ...): number[]`. */
856
+ inline fun JSArray<Double>.mapDouble(f: (Double) -> Double): JSArray<Double> {
857
+ val d = doubles
858
+ if (d != null) {
859
+ val n = dSize
860
+ val out = DoubleArray(n)
861
+ var i = 0
862
+ while (i < n && i < dSize) { out[i] = f(d[i]); i++ }
863
+ return JSArray.ofDoubles(out, i)
864
+ }
865
+ val list = storage
866
+ val n = size
867
+ val out = DoubleArray(n)
868
+ var i = 0
869
+ if (jsTracker == null) {
870
+ while (i < n && i < list.size) { out[i] = f(list[i]); i++ }
871
+ } else {
872
+ while (i < n && i < list.size) { out[i] = f(read(i)); i++ }
873
+ }
874
+ return JSArray.ofDoubles(out, i)
875
+ }
876
+
877
+ /** Unboxed `number[].filter((x) => ...): number[]`. */
878
+ inline fun JSArray<Double>.filterDouble(f: (Double) -> Boolean): JSArray<Double> {
879
+ val d = doubles
880
+ if (d != null) {
881
+ val n = dSize
882
+ var out = DoubleArray(if (n > 16) n ushr 1 else n)
883
+ var count = 0
884
+ var i = 0
885
+ while (i < n && i < dSize) {
886
+ val v = d[i]
887
+ if (f(v)) {
888
+ if (count == out.size) out = out.copyOf(if (count == 0) 8 else count shl 1)
889
+ out[count++] = v
890
+ }
891
+ i++
892
+ }
893
+ return JSArray.ofDoubles(out, count)
894
+ }
895
+ val list = storage
896
+ val n = size
897
+ var out = DoubleArray(if (n > 16) n ushr 1 else n)
898
+ var count = 0
899
+ var i = 0
900
+ if (jsTracker == null) {
901
+ while (i < n && i < list.size) {
902
+ val v = list[i]
903
+ if (f(v)) {
904
+ if (count == out.size) out = out.copyOf(if (count == 0) 8 else count shl 1)
905
+ out[count++] = v
906
+ }
907
+ i++
908
+ }
909
+ } else {
910
+ while (i < n && i < list.size) {
911
+ val v = read(i)
912
+ if (f(v)) {
913
+ if (count == out.size) out = out.copyOf(if (count == 0) 8 else count shl 1)
914
+ out[count++] = v
915
+ }
916
+ i++
917
+ }
918
+ }
919
+ return JSArray.ofDoubles(out, count)
920
+ }
921
+
922
+ /** Unboxed `number[].reduce((a, b) => ..., initial): number`. */
923
+ inline fun JSArray<Double>.reduceDouble(f: (Double, Double) -> Double, initial: Double): Double {
924
+ var acc = initial
925
+ val d = doubles
926
+ if (d != null) {
927
+ val n = dSize
928
+ var i = 0
929
+ while (i < n && i < dSize) { acc = f(acc, d[i]); i++ }
930
+ return acc
931
+ }
932
+ val list = storage
933
+ val n = size
934
+ var i = 0
935
+ if (jsTracker == null) {
936
+ while (i < n && i < list.size) { acc = f(acc, list[i]); i++ }
937
+ } else {
938
+ while (i < n && i < list.size) { acc = f(acc, read(i)); i++ }
939
+ }
940
+ return acc
941
+ }
942
+
943
+ /** Fused single-pass `number[].map(m).filter(p).reduce(r, initial)` with zero intermediate array allocations. */
944
+ inline fun JSArray<Double>.mapFilterReduceDouble(
945
+ map: (Double) -> Double,
946
+ filter: (Double) -> Boolean,
947
+ reduce: (Double, Double) -> Double,
948
+ initial: Double,
949
+ ): Double {
950
+ var acc = initial
951
+ val d = doubles
952
+ if (d != null) {
953
+ val n = dSize
954
+ var i = 0
955
+ while (i < n) {
956
+ val v = map(d[i])
957
+ if (filter(v)) acc = reduce(acc, v)
958
+ i++
959
+ }
960
+ return acc
961
+ }
962
+ val list = storage
963
+ val n = size
964
+ var i = 0
965
+ if (jsTracker == null) {
966
+ while (i < n && i < list.size) {
967
+ val v = map(list[i])
968
+ if (filter(v)) acc = reduce(acc, v)
969
+ i++
970
+ }
971
+ } else {
972
+ while (i < n && i < list.size) {
973
+ val v = map(read(i))
974
+ if (filter(v)) acc = reduce(acc, v)
975
+ i++
976
+ }
977
+ }
978
+ return acc
979
+ }
980
+
981
+ /** Fused single-pass `number[].map(m).reduce(r, initial)` with zero intermediate array allocation. */
982
+ inline fun JSArray<Double>.mapReduceDouble(
983
+ map: (Double) -> Double,
984
+ reduce: (Double, Double) -> Double,
985
+ initial: Double,
986
+ ): Double {
987
+ var acc = initial
988
+ val d = doubles
989
+ if (d != null) {
990
+ val n = dSize
991
+ var i = 0
992
+ while (i < n) { acc = reduce(acc, map(d[i])); i++ }
993
+ return acc
994
+ }
995
+ val list = storage
996
+ val n = size
997
+ var i = 0
998
+ while (i < n && i < list.size) { acc = reduce(acc, map(if (jsTracker == null) list[i] else read(i))); i++ }
999
+ return acc
1000
+ }
1001
+
1002
+ /** Fused single-pass `number[].filter(p).reduce(r, initial)` with zero intermediate array allocation. */
1003
+ inline fun JSArray<Double>.filterReduceDouble(
1004
+ filter: (Double) -> Boolean,
1005
+ reduce: (Double, Double) -> Double,
1006
+ initial: Double,
1007
+ ): Double {
1008
+ var acc = initial
1009
+ val d = doubles
1010
+ if (d != null) {
1011
+ val n = dSize
1012
+ var i = 0
1013
+ while (i < n) {
1014
+ val v = d[i]
1015
+ if (filter(v)) acc = reduce(acc, v)
1016
+ i++
1017
+ }
1018
+ return acc
1019
+ }
1020
+ val list = storage
1021
+ val n = size
1022
+ var i = 0
1023
+ while (i < n && i < list.size) {
1024
+ val v = if (jsTracker == null) list[i] else read(i)
1025
+ if (filter(v)) acc = reduce(acc, v)
1026
+ i++
1027
+ }
1028
+ return acc
1029
+ }
1030
+
1031
+ /** Unboxed in-place stable merge sort for `number[].sort((a, b) => ...)`. */
1032
+ inline fun JSArray<Double>.sortDouble(compare: (Double, Double) -> Double): JSArray<Double> {
1033
+ val d = doubles
1034
+ if (d != null) {
1035
+ val n = dSize
1036
+ if (n >= 2) {
1037
+ var src: DoubleArray = d
1038
+ var dst = DoubleArray(n)
1039
+ var width = 1
1040
+ while (width < n) {
1041
+ var lo = 0
1042
+ while (lo < n) {
1043
+ val mid = minOf(lo + width, n)
1044
+ val hi = minOf(lo + 2 * width, n)
1045
+ if (mid >= hi || !(compare(src[mid], src[mid - 1]) < 0.0)) {
1046
+ System.arraycopy(src, lo, dst, lo, hi - lo)
1047
+ } else {
1048
+ var i = lo
1049
+ var j = mid
1050
+ var k = lo
1051
+ while (i < mid && j < hi) {
1052
+ if (compare(src[j], src[i]) < 0.0) dst[k++] = src[j++] else dst[k++] = src[i++]
1053
+ }
1054
+ while (i < mid) dst[k++] = src[i++]
1055
+ while (j < hi) dst[k++] = src[j++]
1056
+ }
1057
+ lo += 2 * width
1058
+ }
1059
+ val t = src
1060
+ src = dst
1061
+ dst = t
1062
+ width *= 2
1063
+ }
1064
+ if (src !== d) System.arraycopy(src, 0, d, 0, n)
1065
+ }
1066
+ return this
1067
+ }
1068
+ val list = storage
1069
+ val n = list.size
1070
+ val values = arrayOfNulls<Any?>(n)
1071
+ var undefineds: ArrayList<Double>? = null
1072
+ var defined = 0
1073
+ for (e in list) {
1074
+ if (e == null) (undefineds ?: ArrayList<Double>().also { undefineds = it }).add(e)
1075
+ else values[defined++] = e
1076
+ }
1077
+ if (defined >= 2) {
1078
+ var src = values
1079
+ var dst = arrayOfNulls<Any?>(defined)
1080
+ var width = 1
1081
+ while (width < defined) {
1082
+ var lo = 0
1083
+ while (lo < defined) {
1084
+ val mid = minOf(lo + width, defined)
1085
+ val hi = minOf(lo + 2 * width, defined)
1086
+ if (mid >= hi || !(compare(src[mid] as Double, src[mid - 1] as Double) < 0.0)) {
1087
+ System.arraycopy(src, lo, dst, lo, hi - lo)
1088
+ } else {
1089
+ var i = lo
1090
+ var j = mid
1091
+ var k = lo
1092
+ while (i < mid && j < hi) {
1093
+ if (compare(src[j] as Double, src[i] as Double) < 0.0) dst[k++] = src[j++] else dst[k++] = src[i++]
1094
+ }
1095
+ while (i < mid) dst[k++] = src[i++]
1096
+ while (j < hi) dst[k++] = src[j++]
1097
+ }
1098
+ lo += 2 * width
1099
+ }
1100
+ val t = src
1101
+ src = dst
1102
+ dst = t
1103
+ width *= 2
1104
+ }
1105
+ if (src !== values) System.arraycopy(src, 0, values, 0, defined)
1106
+ }
1107
+ val out = ArrayList<Double>(n)
1108
+ for (k in 0 until defined) out.add(values[k] as Double)
1109
+ if (undefineds != null) out.addAll(undefineds)
1110
+ _storage = out
1111
+ doubles = null
1112
+ dSize = 0
1113
+ jsTracker?.trigger()
1114
+ return this
1115
+ }
1116
+
662
1117
  /** `[a, b, c]`. */
663
1118
  fun <T> jsArrayOf(vararg items: T): JSArray<T> = JSArray(items.toList())
664
1119