Skip to content

Commit bcd86f2

Browse files
committed
fix: make Map constructor initialEntires nullable
1 parent 4b5981f commit bcd86f2

File tree

6 files changed

+12993
-17217
lines changed

6 files changed

+12993
-17217
lines changed

std/assembly/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,7 +2394,7 @@ interface NewableFunction extends Function {
23942394
interface IArguments {}
23952395
interface RegExp {}
23962396

2397-
interface Map<K,V> {
2397+
interface Map<K, V> {
23982398
readonly size: i32;
23992399
has(key: K): bool;
24002400
set(key: K, value: V): this;
@@ -2406,10 +2406,10 @@ interface Map<K,V> {
24062406
toString(): string;
24072407
}
24082408

2409-
type MapInitialEntries<K,V> = {key: K, value:V}[]
2409+
type MapInitialEntries<K, V> = {key: K, value: V}[]
24102410

24112411
interface MapConstructor {
2412-
new <K, V>(entries?: MapInitialEntries<K,V>): Map<K,V>;
2412+
new <K, V>(entries?: MapInitialEntries<K, V> | null): Map<K, V>;
24132413
}
24142414

24152415
declare const Map: MapConstructor;

std/assembly/map.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,12 @@ export class Map<K,V> {
7373
private entriesOffset: i32 = 0;
7474
private entriesCount: i32 = 0;
7575

76-
constructor(initialEntries: MapInitialEntries<K,V> = []) {
77-
let entriesLength = initialEntries.length;
78-
79-
if (entriesLength > 0) {
80-
if (entriesLength >= this.entriesCapacity) this.bucketsMask = entriesLength;
76+
constructor(initialEntries: MapInitialEntries<K,V> | null = null) {
77+
if (initialEntries) {
78+
if (initialEntries.length >= this.entriesCapacity) this.bucketsMask = initialEntries.length;
8179
this.rehash((this.bucketsMask << 1) | 1);
8280

83-
for (let i = 0; i < entriesLength; i++) {
81+
for (let i = 0; i < initialEntries.length; i++) {
8482
let key = initialEntries[i].key;
8583
let value = initialEntries[i].value;
8684
let hashCode = HASH<K>(key);

0 commit comments

Comments
 (0)