[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 <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56929}
This commit is contained in:
Clemens Hammacher 2018-10-23 16:15:46 +02:00 committed by Commit Bot
parent bada4d5ccc
commit 4c1e1cb561
2 changed files with 8 additions and 13 deletions

View File

@ -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<uint32_t>(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<int32_t>(pos->second);
} else {
return -1;
}
if (pos == map_.end()) return -1;
return static_cast<int32_t>(pos->second);
}
} // namespace wasm

View File

@ -35,7 +35,6 @@ class V8_EXPORT_PRIVATE SignatureMap {
void Freeze() { frozen_ = true; }
private:
uint32_t next_ = 0;
bool frozen_ = false;
std::unordered_map<FunctionSig, uint32_t, base::hash<FunctionSig>> map_;
};