1 // Copyright 2016 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "src/wasm/signature-map.h" 6 7 #include "src/codegen/signature.h" 8 9 namespace v8 { 10 namespace internal { 11 namespace wasm { 12 FindOrInsert(const FunctionSig & sig)13uint32_t SignatureMap::FindOrInsert(const FunctionSig& sig) { 14 CHECK(!frozen_); 15 auto pos = map_.find(sig); 16 if (pos != map_.end()) return pos->second; 17 // Indexes are returned as int32_t, thus check against their limit. 18 CHECK_GE(kMaxInt, map_.size()); 19 uint32_t index = static_cast<uint32_t>(map_.size()); 20 map_.insert(std::make_pair(sig, index)); 21 return index; 22 } 23 Find(const FunctionSig & sig) const24int32_t SignatureMap::Find(const FunctionSig& sig) const { 25 auto pos = map_.find(sig); 26 if (pos == map_.end()) return -1; 27 return static_cast<int32_t>(pos->second); 28 } 29 30 } // namespace wasm 31 } // namespace internal 32 } // namespace v8 33