diff options
-rw-r--r-- | src/ir/subtypes.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/ir/subtypes.h b/src/ir/subtypes.h index 74c95032d..5a4ff87fc 100644 --- a/src/ir/subtypes.h +++ b/src/ir/subtypes.h @@ -37,7 +37,14 @@ struct SubTypes { } const std::vector<HeapType>& getStrictSubTypes(HeapType type) { - return typeSubTypes[type]; + if (auto iter = typeSubTypes.find(type); iter != typeSubTypes.end()) { + return iter->second; + } + + // No entry exists. Return a canonical constant empty vec, to avoid + // allocation. + static const std::vector<HeapType> empty; + return empty; } // Get all subtypes of a type, and their subtypes and so forth, recursively. @@ -75,6 +82,9 @@ private: } // Maps a type to its subtypes. + // + // After our constructor we never modify this data structure, so we can take + // references to the vectors here safely. std::unordered_map<HeapType, std::vector<HeapType>> typeSubTypes; }; |