Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: src/wasm/signature-map.cc

Issue 2403093002: [wasm] Canonicalize function signature indices for matching in indirect calls. (Closed)
Patch Set: Address review comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/signature-map.h ('k') | src/wasm/wasm-interpreter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 uint32_t SignatureMap::FindOrInsert(FunctionSig* sig) {
12 auto pos = map_.find(sig);
13 if (pos != map_.end()) {
14 return pos->second;
15 } else {
16 uint32_t index = next_++;
17 map_[sig] = index;
18 return index;
19 }
20 }
21
22 int32_t SignatureMap::Find(FunctionSig* sig) const {
23 auto pos = map_.find(sig);
24 if (pos != map_.end()) {
25 return static_cast<int32_t>(pos->second);
26 } else {
27 return -1;
28 }
29 }
30
31 bool SignatureMap::CompareFunctionSigs::operator()(FunctionSig* a,
32 FunctionSig* b) const {
33 if (a == b) return false;
34 if (a->return_count() < b->return_count()) return true;
35 if (a->return_count() > b->return_count()) return false;
36 if (a->parameter_count() < b->parameter_count()) return true;
37 if (a->parameter_count() > b->parameter_count()) return false;
38 for (size_t r = 0; r < a->return_count(); r++) {
39 if (a->GetReturn(r) < b->GetReturn(r)) return true;
40 if (a->GetReturn(r) > b->GetReturn(r)) return false;
41 }
42 for (size_t p = 0; p < a->parameter_count(); p++) {
43 if (a->GetParam(p) < b->GetParam(p)) return true;
44 if (a->GetParam(p) > b->GetParam(p)) return false;
45 }
46 return false;
47 }
48
49 } // namespace wasm
50 } // namespace internal
51 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/signature-map.h ('k') | src/wasm/wasm-interpreter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698