Line data Source code
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/signature.h"
8 :
9 : namespace v8 {
10 : namespace internal {
11 : namespace wasm {
12 :
13 636083 : uint32_t SignatureMap::FindOrInsert(const FunctionSig& sig) {
14 636083 : CHECK(!frozen_);
15 : auto pos = map_.find(sig);
16 636073 : if (pos != map_.end()) return pos->second;
17 : // Indexes are returned as int32_t, thus check against their limit.
18 548044 : CHECK_GE(kMaxInt, map_.size());
19 548044 : uint32_t index = static_cast<uint32_t>(map_.size());
20 548048 : map_.insert(std::make_pair(sig, index));
21 548048 : return index;
22 : }
23 :
24 15510 : int32_t SignatureMap::Find(const FunctionSig& sig) const {
25 : auto pos = map_.find(sig);
26 15510 : if (pos == map_.end()) return -1;
27 13014 : return static_cast<int32_t>(pos->second);
28 : }
29 :
30 : } // namespace wasm
31 : } // namespace internal
32 183867 : } // namespace v8
|