[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) { uint32_t SignatureMap::FindOrInsert(const FunctionSig& sig) {
CHECK(!frozen_); CHECK(!frozen_);
auto pos = map_.find(sig); auto pos = map_.find(sig);
if (pos != map_.end()) { if (pos != map_.end()) return pos->second;
return pos->second; // Indexes are returned as int32_t, thus check against their limit.
} else { CHECK_GE(kMaxInt, map_.size());
uint32_t index = next_++; uint32_t index = static_cast<uint32_t>(map_.size());
map_[sig] = index; map_.insert(std::make_pair(sig, index));
return index; return index;
}
} }
int32_t SignatureMap::Find(const FunctionSig& sig) const { int32_t SignatureMap::Find(const FunctionSig& sig) const {
auto pos = map_.find(sig); auto pos = map_.find(sig);
if (pos != map_.end()) { if (pos == map_.end()) return -1;
return static_cast<int32_t>(pos->second); return static_cast<int32_t>(pos->second);
} else {
return -1;
}
} }
} // namespace wasm } // namespace wasm

View File

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