summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Bradshaw <github@mjb.io>2024-06-24 10:46:59 -0600
committerGitHub <noreply@github.com>2024-06-24 09:46:59 -0700
commitf820d171654de2dcb8cbf7078b4c98336c8e3c69 (patch)
tree3f508155c423a1feba3e21724afc90d98dc4667a
parentf2a39ddeb6ed9fc9399c2ef14305c5efa71007f3 (diff)
downloadwabt-f820d171654de2dcb8cbf7078b4c98336c8e3c69.tar.gz
wabt-f820d171654de2dcb8cbf7078b4c98336c8e3c69.tar.bz2
wabt-f820d171654de2dcb8cbf7078b4c98336c8e3c69.zip
Avoid creating temporary vector copies when checking signature (#2435)
-rw-r--r--include/wabt/type-checker.h4
-rw-r--r--src/type-checker.cc2
2 files changed, 5 insertions, 1 deletions
diff --git a/include/wabt/type-checker.h b/include/wabt/type-checker.h
index 8587a8ac..7b3f4192 100644
--- a/include/wabt/type-checker.h
+++ b/include/wabt/type-checker.h
@@ -18,6 +18,7 @@
#define WABT_TYPE_CHECKER_H_
#include <functional>
+#include <type_traits>
#include <vector>
#include "wabt/common.h"
@@ -182,6 +183,9 @@ class TypeChecker {
template <typename... Args>
void PrintStackIfFailed(Result result, const char* desc, Args... args) {
+ // Assert all args are Type or Type::Enum. If it's a TypeVector then
+ // PrintStackIfFailedV() should be used instead.
+ static_assert((std::is_constructible_v<Type, Args> && ...));
// Minor optimization, check result before constructing the vector to pass
// to the other overload of PrintStackIfFailed.
if (Failed(result)) {
diff --git a/src/type-checker.cc b/src/type-checker.cc
index 823ffd4c..5424f132 100644
--- a/src/type-checker.cc
+++ b/src/type-checker.cc
@@ -254,7 +254,7 @@ Result TypeChecker::CheckSignature(const TypeVector& sig, const char* desc) {
for (size_t i = 0; i < sig.size(); ++i) {
result |= PeekAndCheckType(sig.size() - i - 1, sig[i]);
}
- PrintStackIfFailed(result, desc, sig);
+ PrintStackIfFailedV(result, desc, sig, /*is_end=*/false);
return result;
}