Skip to content

Use uncheked array access for Map#values/keys and Set#values methods #2339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions std/assembly/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class Map<K,V> {
for (let i = 0; i < size; ++i) {
let entry = changetype<MapEntry<K,V>>(start + <usize>i * ENTRY_SIZE<K,V>());
if (!(entry.taggedNext & EMPTY)) {
keys[length++] = entry.key;
unchecked(keys[length++] = entry.key);
}
}
keys.length = length;
Expand All @@ -217,7 +217,7 @@ export class Map<K,V> {
for (let i = 0; i < size; ++i) {
let entry = changetype<MapEntry<K,V>>(start + <usize>i * ENTRY_SIZE<K,V>());
if (!(entry.taggedNext & EMPTY)) {
values[length++] = entry.value;
unchecked(values[length++] = entry.value);
}
}
values.length = length;
Expand Down
2 changes: 1 addition & 1 deletion std/assembly/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class Set<T> {
for (let i = 0; i < size; ++i) {
let entry = changetype<SetEntry<T>>(start + <usize>i * ENTRY_SIZE<T>());
if (!(entry.taggedNext & EMPTY)) {
values[length++] = entry.key;
unchecked(values[length++] = entry.key);
}
}
values.length = length;
Expand Down
72 changes: 36 additions & 36 deletions tests/compiler/issues/2322/index.release.wat
Original file line number Diff line number Diff line change
Expand Up @@ -175,37 +175,37 @@
local.get $4
i32.store offset=4
end
local.get $2
local.get $1
local.get $0
local.get $3
i32.const 4
i32.shl
local.get $2
i32.add
i32.const 2
i32.shl
local.get $0
i32.add
i32.load offset=96
local.get $1
i32.eq
if
local.get $2
local.get $0
local.get $3
i32.const 4
i32.shl
local.get $2
i32.add
i32.const 2
i32.shl
local.get $0
i32.add
local.get $5
i32.store offset=96
local.get $5
i32.eqz
if
local.get $0
local.get $3
i32.const 2
i32.shl
local.get $0
i32.add
local.tee $1
i32.load offset=4
Expand Down Expand Up @@ -356,12 +356,12 @@
call $~lib/builtins/abort
unreachable
end
local.get $2
local.get $4
local.get $1
i32.const 4
i32.add
local.get $2
i32.add
local.get $4
i32.ne
if
i32.const 0
Expand Down Expand Up @@ -422,14 +422,14 @@
call $~lib/builtins/abort
unreachable
end
local.get $2
local.get $0
local.get $5
i32.const 4
i32.shl
local.get $2
i32.add
i32.const 2
i32.shl
local.get $0
i32.add
i32.load offset=96
local.set $3
Expand All @@ -445,14 +445,14 @@
local.get $1
i32.store offset=4
end
local.get $2
local.get $0
local.get $5
i32.const 4
i32.shl
local.get $2
i32.add
i32.const 2
i32.shl
local.get $0
i32.add
local.get $1
i32.store offset=96
Expand All @@ -464,10 +464,10 @@
i32.shl
i32.or
i32.store
local.get $0
local.get $5
i32.const 2
i32.shl
local.get $0
i32.add
local.tee $0
local.get $0
Expand Down Expand Up @@ -504,11 +504,11 @@
i32.load offset=1568
local.tee $4
if
local.get $1
local.get $4
i32.const 4
i32.add
i32.lt_u
local.get $1
i32.gt_u
if
i32.const 0
i32.const 1392
Expand All @@ -517,10 +517,10 @@
call $~lib/builtins/abort
unreachable
end
local.get $4
local.get $1
i32.const 16
i32.sub
local.get $4
i32.eq
if
local.get $4
Expand All @@ -532,11 +532,11 @@
local.set $1
end
else
local.get $1
local.get $0
i32.const 1572
i32.add
i32.lt_u
local.get $1
i32.gt_u
if
i32.const 0
i32.const 1392
Expand Down Expand Up @@ -575,10 +575,10 @@
local.get $1
i32.const 0
i32.store offset=8
local.get $2
local.get $1
i32.const 4
i32.add
local.get $2
i32.add
local.tee $2
i32.const 2
Expand Down Expand Up @@ -635,10 +635,10 @@
i32.const 16
i32.lt_u
if
local.get $1
local.get $0
i32.const 4
i32.shl
local.get $1
i32.add
i32.const 2
i32.shl
Expand Down Expand Up @@ -699,25 +699,25 @@
i32.and
local.set $0
loop $while-continue|1
global.get $~lib/rt/itcms/toSpace
local.get $0
global.get $~lib/rt/itcms/toSpace
i32.ne
if
local.get $0
global.set $~lib/rt/itcms/iter
local.get $1
local.get $0
i32.load offset=4
i32.const 3
i32.and
local.get $1
i32.ne
if
local.get $0
local.get $1
local.get $0
i32.load offset=4
i32.const -4
i32.and
local.get $1
i32.or
i32.store offset=4
i32.const 0
Expand Down Expand Up @@ -774,23 +774,23 @@
i32.and
local.set $0
loop $while-continue|2
global.get $~lib/rt/itcms/toSpace
local.get $0
global.get $~lib/rt/itcms/toSpace
i32.ne
if
local.get $1
local.get $0
i32.load offset=4
i32.const 3
i32.and
local.get $1
i32.ne
if
local.get $0
local.get $1
local.get $0
i32.load offset=4
i32.const -4
i32.and
local.get $1
i32.or
i32.store offset=4
local.get $0
Expand Down Expand Up @@ -943,11 +943,11 @@
i32.and
local.tee $1
if (result i32)
local.get $0
local.get $1
i32.ctz
i32.const 2
i32.shl
local.get $0
i32.add
i32.load offset=96
else
Expand All @@ -957,12 +957,12 @@
i32.and
local.tee $1
if (result i32)
local.get $0
local.get $1
i32.ctz
local.tee $2
i32.const 2
i32.shl
local.get $0
i32.add
i32.load offset=4
local.tee $1
Expand All @@ -975,6 +975,7 @@
call $~lib/builtins/abort
unreachable
end
local.get $0
local.get $1
i32.ctz
local.get $2
Expand All @@ -983,7 +984,6 @@
i32.add
i32.const 2
i32.shl
local.get $0
i32.add
i32.load offset=96
else
Expand Down Expand Up @@ -1277,19 +1277,19 @@
i32.load offset=8
local.set $3
local.get $0
local.get $2
global.get $~lib/rt/itcms/white
local.get $2
i32.or
i32.store offset=4
local.get $0
local.get $3
i32.store offset=8
local.get $3
local.get $0
local.get $3
i32.load offset=4
i32.const 3
i32.and
local.get $0
i32.or
i32.store offset=4
local.get $2
Expand Down Expand Up @@ -1350,8 +1350,8 @@
i32.and
i32.eq
if
global.get $~lib/rt/itcms/iter
local.get $1
global.get $~lib/rt/itcms/iter
i32.eq
if
local.get $1
Expand Down Expand Up @@ -1411,11 +1411,11 @@
local.get $2
i32.store offset=8
local.get $2
local.get $0
local.get $2
i32.load offset=4
i32.const 3
i32.and
local.get $0
i32.or
i32.store offset=4
end
Expand All @@ -1429,10 +1429,10 @@
if (result i32)
i32.const 1
else
local.get $0
i32.const 1440
i32.load
local.get $0
i32.lt_u
i32.gt_u
if
i32.const 1248
i32.const 1312
Expand Down Expand Up @@ -1469,11 +1469,11 @@
local.get $0
i32.store offset=8
local.get $0
local.get $1
local.get $0
i32.load offset=4
i32.const 3
i32.and
local.get $1
i32.or
i32.store offset=4
local.get $2
Expand Down
Loading