Skip to content

Commit 0bea37c

Browse files
MaxGraeydcodeIO
authored andcommitted
Simplify Array#splice & improve tests (AssemblyScript#910)
1 parent c7740fe commit 0bea37c

File tree

8 files changed

+4533
-3002
lines changed

8 files changed

+4533
-3002
lines changed

std/assembly/array.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -400,20 +400,12 @@ export class Array<T> extends ArrayBufferView {
400400
var resultStart = result.dataStart;
401401
var thisStart = this.dataStart;
402402
var thisBase = thisStart + (<usize>start << alignof<T>());
403-
if (isManaged<T>()) {
404-
for (let i = 0; i < deleteCount; ++i) {
405-
store<usize>(resultStart + (<usize>i << alignof<T>()),
406-
load<usize>(thisBase + (<usize>i << alignof<T>()))
407-
);
408-
// no need to retain -> is moved
409-
}
410-
} else {
411-
memory.copy(
412-
resultStart,
413-
thisBase,
414-
<usize>deleteCount << alignof<T>()
415-
);
416-
}
403+
// no need to retain -> is moved
404+
memory.copy(
405+
resultStart,
406+
thisBase,
407+
<usize>deleteCount << alignof<T>()
408+
);
417409
var offset = start + deleteCount;
418410
if (length != offset) {
419411
memory.copy(

std/assembly/index.d.ts

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ declare function fmod(x: f64, y: f64): f64;
183183
/** Returns the 32-bit floating-point remainder of `x/y`. */
184184
declare function fmodf(x: f32, y: f32): f32;
185185
/** Returns the number of parameters in the given function signature type. */
186-
declare function lengthof<T extends (...args: any) => any>(func?: T): i32;
186+
declare function lengthof<T extends (...args: any[]) => any>(func?: T): i32;
187187

188188
/** Atomic operations. */
189189
declare namespace atomic {
@@ -1356,6 +1356,7 @@ declare class String {
13561356
split(separator?: string, limit?: i32): string[];
13571357
toString(): string;
13581358
}
1359+
13591360
declare namespace String {
13601361
/** Encoding helpers for UTF-8. */
13611362
export namespace UTF8 {
@@ -1381,6 +1382,32 @@ declare namespace String {
13811382
}
13821383
}
13831384

1385+
declare class Object {
1386+
/** The Object.is() method determines whether two values are the same value. */
1387+
static is<T>(value1: T, value2: T): bool;
1388+
}
1389+
1390+
declare class Date {
1391+
/** Returns the UTC timestamp in milliseconds of the specified date. */
1392+
static UTC(
1393+
year: i32,
1394+
month: i32,
1395+
day: i32,
1396+
hour: i32,
1397+
minute: i32,
1398+
second: i32,
1399+
millisecond: i32
1400+
): i64;
1401+
/** Returns the current UTC timestamp in milliseconds. */
1402+
static now(): i64;
1403+
/** Constructs a new date object from an UTC timestamp in milliseconds. */
1404+
constructor(value: i64);
1405+
/** Returns the UTC timestamp of this date in milliseconds. */
1406+
getTime(): i64;
1407+
/** Sets the UTC timestamp of this date in milliseconds. */
1408+
setTime(value: i64): i64;
1409+
}
1410+
13841411
/** Class for representing a runtime error. Base class of all errors. */
13851412
declare class Error {
13861413

@@ -1412,12 +1439,13 @@ declare class SyntaxError extends Error { }
14121439
interface Boolean {
14131440
toString(): string;
14141441
}
1415-
interface Function {}
1416-
interface IArguments {}
1442+
14171443
interface Number {
14181444
toString(radix?: number): string;
14191445
}
1420-
interface Object {}
1446+
1447+
interface Function {}
1448+
interface IArguments {}
14211449
interface RegExp {}
14221450

14231451
declare class Map<K,V> {
@@ -1581,32 +1609,6 @@ declare const Math: IMath<f64>;
15811609
/** Alias of {@link NativeMathf} or {@link JSMath} respectively. Defaults to `NativeMathf`. */
15821610
declare const Mathf: IMath<f32>;
15831611

1584-
declare class Date {
1585-
/** Returns the UTC timestamp in milliseconds of the specified date. */
1586-
static UTC(
1587-
year: i32,
1588-
month: i32,
1589-
day: i32,
1590-
hour: i32,
1591-
minute: i32,
1592-
second: i32,
1593-
millisecond: i32
1594-
): i64;
1595-
/** Returns the current UTC timestamp in milliseconds. */
1596-
static now(): i64;
1597-
/** Constructs a new date object from an UTC timestamp in milliseconds. */
1598-
constructor(value: i64);
1599-
/** Returns the UTC timestamp of this date in milliseconds. */
1600-
getTime(): i64;
1601-
/** Sets the UTC timestamp of this date in milliseconds. */
1602-
setTime(value: i64): i64;
1603-
}
1604-
1605-
declare class Object {
1606-
/** The Object.is() method determines whether two values are the same value. */
1607-
static is<T>(value1: T, value2: T): bool;
1608-
}
1609-
16101612
/** Environmental tracing function for debugging purposes. */
16111613
declare function trace(msg: string, n?: i32, a0?: f64, a1?: f64, a2?: f64, a3?: f64, a4?: f64): void;
16121614

tests/compiler/std/array.optimized.wat

Lines changed: 1910 additions & 1332 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)