diff options
author | Alon Zakai <azakai@google.com> | 2022-01-14 08:55:47 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-14 08:55:47 -0800 |
commit | 31e8803e9fa6164797ebcd53371dbcee3e6bc0e2 (patch) | |
tree | 2849df71f16ca501b6ea4f93231ebbc01d068a2d /src/literal.h | |
parent | 6cb41eca43b8a6045b0138545c6b4fcdfcf4448a (diff) | |
download | binaryen-31e8803e9fa6164797ebcd53371dbcee3e6bc0e2.tar.gz binaryen-31e8803e9fa6164797ebcd53371dbcee3e6bc0e2.tar.bz2 binaryen-31e8803e9fa6164797ebcd53371dbcee3e6bc0e2.zip |
Add fast paths for Literals::getType (#4454)
In the common case, avoid allocating a vector and calling malloc.
This makes us over 3x faster on the benchmark in #4452
Diffstat (limited to 'src/literal.h')
-rw-r--r-- | src/literal.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/literal.h b/src/literal.h index 727865c94..4ad81268e 100644 --- a/src/literal.h +++ b/src/literal.h @@ -693,6 +693,12 @@ public: Literals(size_t initialSize) : SmallVector(initialSize) {} Type getType() { + if (empty()) { + return Type::none; + } + if (size() == 1) { + return (*this)[0].type; + } std::vector<Type> types; for (auto& val : *this) { types.push_back(val.type); |