From 9d50c1f4a7fb81ead03a2b8445655f157553fa1b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 9 Oct 2020 10:40:01 -0700 Subject: Optimize getLoggableTypes in fuzzer, and add isLoggableType (#3208) Previously getLoggableType would allocate a vector every time. This caches it. Also add isLoggableType which will need this caching as I will be calling it quite a lot in a future patch to the fuzzer. --- src/tools/fuzzing.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h index ecc548e22..088aa3c96 100644 --- a/src/tools/fuzzing.h +++ b/src/tools/fuzzing.h @@ -2803,17 +2803,27 @@ private: // removed during optimization // - there's no point in logging externref or anyref because these are opaque // - don't bother logging tuples - std::vector getLoggableTypes() { - return items( - FeatureOptions() - .add(FeatureSet::MVP, Type::i32, Type::i64, Type::f32, Type::f64) - .add(FeatureSet::SIMD, Type::v128) - .add(FeatureSet::ReferenceTypes | FeatureSet::ExceptionHandling, - Type::exnref)); + std::vector loggableTypes; + + const std::vector& getLoggableTypes() { + if (loggableTypes.empty()) { + loggableTypes = items( + FeatureOptions() + .add(FeatureSet::MVP, Type::i32, Type::i64, Type::f32, Type::f64) + .add(FeatureSet::SIMD, Type::v128) + .add(FeatureSet::ReferenceTypes | FeatureSet::ExceptionHandling, + Type::exnref)); + } + return loggableTypes; } Type getLoggableType() { return pick(getLoggableTypes()); } + bool isLoggableType(Type type) { + const auto& types = getLoggableTypes(); + return std::find(types.begin(), types.end(), type) != types.end(); + } + // statistical distributions // 0 to the limit, logarithmic scale -- cgit v1.2.3