summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/wasm-type.h6
-rw-r--r--src/wasm/wasm-type.cpp24
2 files changed, 20 insertions, 10 deletions
diff --git a/src/wasm-type.h b/src/wasm-type.h
index 4a55d7b33..9019dfc9e 100644
--- a/src/wasm-type.h
+++ b/src/wasm-type.h
@@ -158,7 +158,7 @@ public:
FeatureSet getFeatures() const;
// Gets the heap type corresponding to this type
- HeapType getHeapType() const;
+ const HeapType& getHeapType() const;
// Returns a number type based on its size in bytes and whether it is a float
// type.
@@ -365,12 +365,12 @@ struct HeapType {
return signature;
}
bool isStruct() const { return kind == StructKind; }
- Struct getStruct() const {
+ const Struct& getStruct() const {
assert(isStruct() && "Not a struct");
return struct_;
}
bool isArray() const { return kind == ArrayKind; }
- Array getArray() const {
+ const Array& getArray() const {
assert(isArray() && "Not an array");
return array;
}
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index b323dcc06..a810f6f98 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -513,24 +513,34 @@ FeatureSet Type::getFeatures() const {
return getSingleFeatures(*this);
}
-HeapType Type::getHeapType() const {
+// getHeapType() returns a const HeapType&, so we need a canonical object to
+// return for the basic types, so that we don't create a temporary copy on each
+// call.
+namespace statics {
+static HeapType funcHeapType(HeapType::FuncKind),
+ externHeapType(HeapType::ExternKind), exnHeapType(HeapType::ExnKind),
+ anyHeapType(HeapType::AnyKind), eqHeapType(HeapType::EqKind),
+ i31HeapType(HeapType::I31Kind);
+}
+
+const HeapType& Type::getHeapType() const {
if (isRef()) {
if (isCompound()) {
return getTypeInfo(*this)->ref.heapType;
}
switch (getBasic()) {
case funcref:
- return HeapType::FuncKind;
+ return statics::funcHeapType;
case externref:
- return HeapType::ExternKind;
+ return statics::externHeapType;
case exnref:
- return HeapType::ExnKind;
+ return statics::exnHeapType;
case anyref:
- return HeapType::AnyKind;
+ return statics::anyHeapType;
case eqref:
- return HeapType::EqKind;
+ return statics::eqHeapType;
case i31ref:
- return HeapType::I31Kind;
+ return statics::i31HeapType;
default:
break;
}