[Wasm] Pull array range checks into single function

This commit is contained in:
Igor Laevsky
2022-03-31 15:32:30 +03:00
committed by teamcity
parent 6f448820f0
commit 2c9bfe901d
3 changed files with 22 additions and 18 deletions
@@ -41,7 +41,7 @@ public class Array<T> constructor(size: Int) {
*/
@Suppress("UNCHECKED_CAST")
public operator fun get(index: Int): T {
if (index < 0 || index >= storage.len()) throw IndexOutOfBoundsException()
rangeCheck(index, storage.len())
return storage.get(index) as T
}
@@ -56,7 +56,7 @@ public class Array<T> constructor(size: Int) {
* where the behavior is unspecified.
*/
public operator fun set(index: Int, value: T) {
if (index < 0 || index >= storage.len()) throw IndexOutOfBoundsException()
rangeCheck(index, storage.len())
storage.set(index, value)
}