Chromium Code Reviews| OLD | NEW |
|---|---|
| 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() { | |
|
Clemens Hammacher
2017/07/24 15:39:48
you can just use ": mutex_(new base::Mutex())" (as
| |
| 12 mutex_ = std::unique_ptr<base::Mutex>(new base::Mutex()); | |
| 13 } | |
| 14 | |
| 11 uint32_t SignatureMap::FindOrInsert(FunctionSig* sig) { | 15 uint32_t SignatureMap::FindOrInsert(FunctionSig* sig) { |
| 16 base::LockGuard<base::Mutex> guard(mutex_.get()); | |
| 12 auto pos = map_.find(sig); | 17 auto pos = map_.find(sig); |
| 13 if (pos != map_.end()) { | 18 if (pos != map_.end()) { |
| 14 return pos->second; | 19 return pos->second; |
| 15 } else { | 20 } else { |
| 16 uint32_t index = next_++; | 21 uint32_t index = next_++; |
| 17 map_[sig] = index; | 22 map_[sig] = index; |
| 18 return index; | 23 return index; |
| 19 } | 24 } |
| 20 } | 25 } |
| 21 | 26 |
| 22 int32_t SignatureMap::Find(FunctionSig* sig) const { | 27 int32_t SignatureMap::Find(FunctionSig* sig) const { |
| 28 base::LockGuard<base::Mutex> guard(mutex_.get()); | |
| 23 auto pos = map_.find(sig); | 29 auto pos = map_.find(sig); |
| 24 if (pos != map_.end()) { | 30 if (pos != map_.end()) { |
| 25 return static_cast<int32_t>(pos->second); | 31 return static_cast<int32_t>(pos->second); |
| 26 } else { | 32 } else { |
| 27 return -1; | 33 return -1; |
| 28 } | 34 } |
| 29 } | 35 } |
| 30 | 36 |
| 31 bool SignatureMap::CompareFunctionSigs::operator()(FunctionSig* a, | 37 bool SignatureMap::CompareFunctionSigs::operator()(FunctionSig* a, |
| 32 FunctionSig* b) const { | 38 FunctionSig* b) const { |
| 33 if (a == b) return false; | 39 if (a == b) return false; |
| 34 if (a->return_count() < b->return_count()) return true; | 40 if (a->return_count() < b->return_count()) return true; |
| 35 if (a->return_count() > b->return_count()) return false; | 41 if (a->return_count() > b->return_count()) return false; |
| 36 if (a->parameter_count() < b->parameter_count()) return true; | 42 if (a->parameter_count() < b->parameter_count()) return true; |
| 37 if (a->parameter_count() > b->parameter_count()) return false; | 43 if (a->parameter_count() > b->parameter_count()) return false; |
| 38 for (size_t r = 0; r < a->return_count(); r++) { | 44 for (size_t r = 0; r < a->return_count(); r++) { |
| 39 if (a->GetReturn(r) < b->GetReturn(r)) return true; | 45 if (a->GetReturn(r) < b->GetReturn(r)) return true; |
| 40 if (a->GetReturn(r) > b->GetReturn(r)) return false; | 46 if (a->GetReturn(r) > b->GetReturn(r)) return false; |
| 41 } | 47 } |
| 42 for (size_t p = 0; p < a->parameter_count(); p++) { | 48 for (size_t p = 0; p < a->parameter_count(); p++) { |
| 43 if (a->GetParam(p) < b->GetParam(p)) return true; | 49 if (a->GetParam(p) < b->GetParam(p)) return true; |
| 44 if (a->GetParam(p) > b->GetParam(p)) return false; | 50 if (a->GetParam(p) > b->GetParam(p)) return false; |
| 45 } | 51 } |
| 46 return false; | 52 return false; |
| 47 } | 53 } |
| 48 | 54 |
| 49 } // namespace wasm | 55 } // namespace wasm |
| 50 } // namespace internal | 56 } // namespace internal |
| 51 } // namespace v8 | 57 } // namespace v8 |
| OLD | NEW |