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

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

Issue 2981883002: [wasm] More extensive indirect dispatch signature mismatch tests. (Closed)
Patch Set: Shorter constructor Created 3 years, 4 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') | test/mjsunit/wasm/indirect-sig-mismatch.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/wasm/signature-map.h" 5 #include "src/wasm/signature-map.h"
6 6
7 namespace v8 { 7 namespace v8 {
8 namespace internal { 8 namespace internal {
9 namespace wasm { 9 namespace wasm {
10 10
11 SignatureMap::SignatureMap() : mutex_(new base::Mutex()) {}
12
11 uint32_t SignatureMap::FindOrInsert(FunctionSig* sig) { 13 uint32_t SignatureMap::FindOrInsert(FunctionSig* sig) {
14 base::LockGuard<base::Mutex> guard(mutex_.get());
12 auto pos = map_.find(sig); 15 auto pos = map_.find(sig);
13 if (pos != map_.end()) { 16 if (pos != map_.end()) {
14 return pos->second; 17 return pos->second;
15 } else { 18 } else {
16 uint32_t index = next_++; 19 uint32_t index = next_++;
17 map_[sig] = index; 20 map_[sig] = index;
18 return index; 21 return index;
19 } 22 }
20 } 23 }
21 24
22 int32_t SignatureMap::Find(FunctionSig* sig) const { 25 int32_t SignatureMap::Find(FunctionSig* sig) const {
26 base::LockGuard<base::Mutex> guard(mutex_.get());
23 auto pos = map_.find(sig); 27 auto pos = map_.find(sig);
24 if (pos != map_.end()) { 28 if (pos != map_.end()) {
25 return static_cast<int32_t>(pos->second); 29 return static_cast<int32_t>(pos->second);
26 } else { 30 } else {
27 return -1; 31 return -1;
28 } 32 }
29 } 33 }
30 34
31 bool SignatureMap::CompareFunctionSigs::operator()(FunctionSig* a, 35 bool SignatureMap::CompareFunctionSigs::operator()(FunctionSig* a,
32 FunctionSig* b) const { 36 FunctionSig* b) const {
33 if (a == b) return false; 37 if (a == b) return false;
34 if (a->return_count() < b->return_count()) return true; 38 if (a->return_count() < b->return_count()) return true;
35 if (a->return_count() > b->return_count()) return false; 39 if (a->return_count() > b->return_count()) return false;
36 if (a->parameter_count() < b->parameter_count()) return true; 40 if (a->parameter_count() < b->parameter_count()) return true;
37 if (a->parameter_count() > b->parameter_count()) return false; 41 if (a->parameter_count() > b->parameter_count()) return false;
38 for (size_t r = 0; r < a->return_count(); r++) { 42 for (size_t r = 0; r < a->return_count(); r++) {
39 if (a->GetReturn(r) < b->GetReturn(r)) return true; 43 if (a->GetReturn(r) < b->GetReturn(r)) return true;
40 if (a->GetReturn(r) > b->GetReturn(r)) return false; 44 if (a->GetReturn(r) > b->GetReturn(r)) return false;
41 } 45 }
42 for (size_t p = 0; p < a->parameter_count(); p++) { 46 for (size_t p = 0; p < a->parameter_count(); p++) {
43 if (a->GetParam(p) < b->GetParam(p)) return true; 47 if (a->GetParam(p) < b->GetParam(p)) return true;
44 if (a->GetParam(p) > b->GetParam(p)) return false; 48 if (a->GetParam(p) > b->GetParam(p)) return false;
45 } 49 }
46 return false; 50 return false;
47 } 51 }
48 52
49 } // namespace wasm 53 } // namespace wasm
50 } // namespace internal 54 } // namespace internal
51 } // namespace v8 55 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/signature-map.h ('k') | test/mjsunit/wasm/indirect-sig-mismatch.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698