From 4c1e1cb5616e1a8f6e21768dc1719e92113a5d40 Mon Sep 17 00:00:00 2001 From: Clemens Hammacher Date: Tue, 23 Oct 2018 16:15:46 +0200 Subject: [PATCH] [wasm] Simplify SignatureMap Minor simplifications and an additional overflow check. R=mstarzinger@chromium.org Bug: v8:8238 Change-Id: I169464319a0e70562f3a443f429e462d30dd2fa3 Reviewed-on: https://chromium-review.googlesource.com/c/1296482 Reviewed-by: Michael Starzinger Commit-Queue: Clemens Hammacher Cr-Commit-Position: refs/heads/master@{#56929} --- src/wasm/signature-map.cc | 20 ++++++++------------ src/wasm/signature-map.h | 1 - 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/wasm/signature-map.cc b/src/wasm/signature-map.cc index dca3b1ef89..5f494aca62 100644 --- a/src/wasm/signature-map.cc +++ b/src/wasm/signature-map.cc @@ -13,22 +13,18 @@ namespace wasm { uint32_t SignatureMap::FindOrInsert(const FunctionSig& sig) { CHECK(!frozen_); auto pos = map_.find(sig); - if (pos != map_.end()) { - return pos->second; - } else { - uint32_t index = next_++; - map_[sig] = index; - return index; - } + if (pos != map_.end()) return pos->second; + // Indexes are returned as int32_t, thus check against their limit. + CHECK_GE(kMaxInt, map_.size()); + uint32_t index = static_cast(map_.size()); + map_.insert(std::make_pair(sig, index)); + return index; } int32_t SignatureMap::Find(const FunctionSig& sig) const { auto pos = map_.find(sig); - if (pos != map_.end()) { - return static_cast(pos->second); - } else { - return -1; - } + if (pos == map_.end()) return -1; + return static_cast(pos->second); } } // namespace wasm diff --git a/src/wasm/signature-map.h b/src/wasm/signature-map.h index c26c20f586..04c6b2efa5 100644 --- a/src/wasm/signature-map.h +++ b/src/wasm/signature-map.h @@ -35,7 +35,6 @@ class V8_EXPORT_PRIVATE SignatureMap { void Freeze() { frozen_ = true; } private: - uint32_t next_ = 0; bool frozen_ = false; std::unordered_map> map_; };