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

Side by Side Diff: src/wasm/switch-logic.cc

Issue 2094573002: [wasm] Cleaning up code (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 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/module-decoder.cc ('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
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/switch-logic.h" 5 #include "src/wasm/switch-logic.h"
6 6
7 namespace v8 { 7 namespace v8 {
8 namespace internal { 8 namespace internal {
9 namespace wasm { 9 namespace wasm {
10 10
(...skipping 16 matching lines...) Expand all
27 } // namespace 27 } // namespace
28 28
29 CaseNode* OrderCases(ZoneVector<int>* cases, Zone* zone) { 29 CaseNode* OrderCases(ZoneVector<int>* cases, Zone* zone) {
30 const int max_distance = 2; 30 const int max_distance = 2;
31 const int min_size = 4; 31 const int min_size = 4;
32 if (cases->empty()) { 32 if (cases->empty()) {
33 return nullptr; 33 return nullptr;
34 } 34 }
35 std::sort(cases->begin(), cases->end()); 35 std::sort(cases->begin(), cases->end());
36 ZoneVector<size_t> table_breaks(zone); 36 ZoneVector<size_t> table_breaks(zone);
37 for (size_t i = 1; i < cases->size(); i++) { 37 for (size_t i = 1; i < cases->size(); ++i) {
38 if (cases->at(i) - cases->at(i - 1) > max_distance) { 38 if (cases->at(i) - cases->at(i - 1) > max_distance) {
39 table_breaks.push_back(i); 39 table_breaks.push_back(i);
40 } 40 }
41 } 41 }
42 table_breaks.push_back(cases->size()); 42 table_breaks.push_back(cases->size());
43 ZoneVector<CaseNode*> nodes(zone); 43 ZoneVector<CaseNode*> nodes(zone);
44 size_t curr_pos = 0; 44 size_t curr_pos = 0;
45 for (size_t i = 0; i < table_breaks.size(); i++) { 45 for (size_t i = 0; i < table_breaks.size(); ++i) {
46 size_t break_pos = table_breaks[i]; 46 size_t break_pos = table_breaks[i];
47 if (break_pos - curr_pos >= min_size) { 47 if (break_pos - curr_pos >= min_size) {
48 int begin = cases->at(curr_pos); 48 int begin = cases->at(curr_pos);
49 int end = cases->at(break_pos - 1); 49 int end = cases->at(break_pos - 1);
50 nodes.push_back(new (zone) CaseNode(begin, end)); 50 nodes.push_back(new (zone) CaseNode(begin, end));
51 curr_pos = break_pos; 51 curr_pos = break_pos;
52 } else { 52 } else {
53 for (; curr_pos < break_pos; curr_pos++) { 53 for (; curr_pos < break_pos; curr_pos++) {
54 nodes.push_back(new (zone) 54 nodes.push_back(new (zone)
55 CaseNode(cases->at(curr_pos), cases->at(curr_pos))); 55 CaseNode(cases->at(curr_pos), cases->at(curr_pos)));
56 } 56 }
57 } 57 }
58 } 58 }
59 return CreateBst(&nodes, 0, nodes.size() - 1); 59 return CreateBst(&nodes, 0, nodes.size() - 1);
60 } 60 }
61 } // namespace wasm 61 } // namespace wasm
62 } // namespace internal 62 } // namespace internal
63 } // namespace v8 63 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/module-decoder.cc ('k') | src/wasm/wasm-interpreter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698