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 567768 : uint32_t SignatureMap::FindOrInsert(const FunctionSig& sig) {
14 567768 : CHECK(!frozen_);
15 : auto pos = map_.find(sig);
16 567766 : if (pos != map_.end()) return pos->second;
17 : // Indexes are returned as int32_t, thus check against their limit.
18 489157 : CHECK_GE(kMaxInt, map_.size());
19 489157 : uint32_t index = static_cast<uint32_t>(map_.size());
20 489161 : map_.insert(std::make_pair(sig, index));
21 489161 : return index;
22 : }
23 :
24 14548 : int32_t SignatureMap::Find(const FunctionSig& sig) const {
25 : auto pos = map_.find(sig);
26 14548 : if (pos == map_.end()) return -1;
27 11672 : return static_cast<int32_t>(pos->second);
28 : }
29 :
30 : } // namespace wasm
31 : } // namespace internal
32 178779 : } // namespace v8
|