summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2020-04-09 17:42:36 -0700
committerGitHub <noreply@github.com>2020-04-09 17:42:36 -0700
commit1b56c2b341e838656adca9a7101d824ed757d6ad (patch)
treeda49e1f8d2b8d48628783b25229681d23d266beb /src
parentc2760038591df9e67b49bb71c9aedb70eadb5b11 (diff)
downloadbinaryen-1b56c2b341e838656adca9a7101d824ed757d6ad.tar.gz
binaryen-1b56c2b341e838656adca9a7101d824ed757d6ad.tar.bz2
binaryen-1b56c2b341e838656adca9a7101d824ed757d6ad.zip
Optimize uint32_t Type constructor (#2744)
Avoid taking the type interning lock to look up the size when the provided ID corresponds to a statically known type. This eliminates a considerable amount of unnecessary lock traffic when using the C or JS APIs.
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-type.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index aed13b6d1..30bd74e6a 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -138,8 +138,11 @@ Type::Type(std::initializer_list<Type> types) { init(types); }
Type::Type(const std::vector<Type>& types) { init(types); }
Type::Type(uint32_t _id) {
- id = _id;
- {
+ if (_id <= last_value_type) {
+ *this = Type(static_cast<ValueType>(_id));
+ } else {
+ id = _id;
+ // Unknown complex type; look up the size
std::shared_lock<std::shared_timed_mutex> lock(mutex);
_size = typeLists[id]->size();
}