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 : namespace v8 {
8 : namespace internal {
9 : namespace wasm {
10 :
11 37445 : uint32_t SignatureMap::FindOrInsert(FunctionSig* sig) {
12 : auto pos = map_.find(sig);
13 37445 : if (pos != map_.end()) {
14 7759 : return pos->second;
15 : } else {
16 29686 : uint32_t index = next_++;
17 29686 : map_[sig] = index;
18 29686 : return index;
19 : }
20 : }
21 :
22 58136 : int32_t SignatureMap::Find(FunctionSig* sig) const {
23 : auto pos = map_.find(sig);
24 58136 : if (pos != map_.end()) {
25 32169 : return static_cast<int32_t>(pos->second);
26 : } else {
27 : return -1;
28 : }
29 : }
30 :
31 413588 : bool SignatureMap::CompareFunctionSigs::operator()(FunctionSig* a,
32 272353 : FunctionSig* b) const {
33 141235 : if (a == b) return false;
34 105541 : if (a->return_count() < b->return_count()) return true;
35 81139 : if (a->return_count() > b->return_count()) return false;
36 65651 : if (a->parameter_count() < b->parameter_count()) return true;
37 52864 : if (a->parameter_count() > b->parameter_count()) return false;
38 44042 : for (size_t r = 0; r < a->return_count(); r++) {
39 45002 : if (a->GetReturn(r) < b->GetReturn(r)) return true;
40 44295 : if (a->GetReturn(r) > b->GetReturn(r)) return false;
41 : }
42 55780 : for (size_t p = 0; p < a->parameter_count(); p++) {
43 56159 : if (a->GetParam(p) < b->GetParam(p)) return true;
44 55828 : if (a->GetParam(p) > b->GetParam(p)) return false;
45 : }
46 : return false;
47 : }
48 :
49 : } // namespace wasm
50 : } // namespace internal
51 : } // namespace v8
|