Skip to content

Commit c0b31cd

Browse files
committed
avoid local static for efficiency
1 parent 9ee9393 commit c0b31cd

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/wasm/wasm-type.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,14 +2731,23 @@ std::unordered_set<HeapType> getIgnorablePublicTypes() {
27312731

27322732
namespace wasm::HeapTypes {
27332733

2734+
// We could get laziness for free by making these local statics, but that would
2735+
// come with unnecessary implicity synchronization overhead.
2736+
static std::optional<HeapType> theMutI8Array;
2737+
static std::optional<HeapType> theMutI16Array;
2738+
27342739
HeapType getMutI8Array() {
2735-
static HeapType i8Array = Array(Field(Field::i8, Mutable));
2736-
return i8Array;
2740+
if (!theMutI8Array) {
2741+
theMutI8Array = Array(Field(Field::i8, Mutable));
2742+
}
2743+
return *theMutI8Array;
27372744
}
27382745

27392746
HeapType getMutI16Array() {
2740-
static HeapType i16Array = Array(Field(Field::i16, Mutable));
2741-
return i16Array;
2747+
if (!theMutI16Array) {
2748+
theMutI16Array = Array(Field(Field::i16, Mutable));
2749+
}
2750+
return *theMutI16Array;
27422751
}
27432752

27442753
} // namespace wasm::HeapTypes

0 commit comments

Comments
 (0)