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

Side by Side Diff: tools/turbolizer/selection-broker.js

Issue 2230083004: [turbolizer] Use locations rather than ranges everywhere (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove stray change Created 4 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 | « tools/turbolizer/selection.js ('k') | tools/turbolizer/text-view.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 var SelectionBroker = function() { 5 var SelectionBroker = function() {
6 this.brokers = []; 6 this.brokers = [];
7 this.dispatching = false; 7 this.dispatching = false;
8 this.lastDispatchingHandler = null; 8 this.lastDispatchingHandler = null;
9 this.nodePositionMap = [];
10 this.sortedPositionList = [];
11 this.positionNodeMap = [];
9 }; 12 };
10 13
11 SelectionBroker.prototype.addSelectionHandler = function(handler) { 14 SelectionBroker.prototype.addSelectionHandler = function(handler) {
12 this.brokers.push(handler); 15 this.brokers.push(handler);
13 } 16 }
14 17
15 SelectionBroker.prototype.select = function(from, ranges, selected) { 18 SelectionBroker.prototype.setNodePositionMap = function(map) {
16 if (!this.dispatching) { 19 let broker = this;
17 this.lastDispatchingHandler = from; 20 if (!map) return;
21 broker.nodePositionMap = map;
22 broker.positionNodeMap = [];
23 broker.sortedPositionList = [];
24 let next = 0;
25 for (let i in broker.nodePositionMap) {
26 broker.sortedPositionList[next] = Number(broker.nodePositionMap[i]);
27 broker.positionNodeMap[next++] = i;
28 }
29 broker.sortedPositionList = sortUnique(broker.sortedPositionList,
30 function(a,b) { return a - b; });
31 this.positionNodeMap.sort(function(a,b) {
32 let result = broker.nodePositionMap[a] - broker.nodePositionMap[b];
33 if (result != 0) return result;
34 return a - b;
35 });
36 }
37
38 SelectionBroker.prototype.select = function(from, locations, selected) {
39 let broker = this;
40 if (!broker.dispatching) {
41 broker.lastDispatchingHandler = from;
18 try { 42 try {
19 this.dispatching = true; 43 broker.dispatching = true;
44 let enrichLocations = function(locations) {
45 result = [];
46 for (let location of locations) {
47 let newLocation = {};
48 if (location.pos_start != undefined) {
49 newLocation.pos_start = location.pos_start;
50 }
51 if (location.pos_end != undefined) {
52 newLocation.pos_end = location.pos_end;
53 }
54 if (location.node_id != undefined) {
55 newLocation.node_id = location.node_id;
56 }
57 if (location.block_id != undefined) {
58 newLocation.block_id = location.block_id;
59 }
60 if (newLocation.pos_start == undefined &&
61 newLocation.pos_end == undefined &&
62 newLocation.node_id != undefined) {
63 if (broker.nodePositionMap && broker.nodePositionMap[location.node_i d]) {
64 newLocation.pos_start = broker.nodePositionMap[location.node_id];
65 newLocation.pos_end = location.pos_start + 1;
66 }
67 }
68 result.push(newLocation);
69 }
70 return result;
71 }
72 locations = enrichLocations(locations);
20 for (var b of this.brokers) { 73 for (var b of this.brokers) {
21 if (b != from) { 74 if (b != from) {
22 b.brokeredSelect(ranges, selected); 75 b.brokeredSelect(locations, selected);
23 } 76 }
24 } 77 }
25 } 78 }
26 finally { 79 finally {
27 this.dispatching = false; 80 broker.dispatching = false;
28 } 81 }
29 } 82 }
30 } 83 }
31 84
32 SelectionBroker.prototype.clear = function(from) { 85 SelectionBroker.prototype.clear = function(from) {
33 this.lastDispatchingHandler = null; 86 this.lastDispatchingHandler = null;
34 if (!this.dispatching) { 87 if (!this.dispatching) {
35 try { 88 try {
36 this.dispatching = true; 89 this.dispatching = true;
37 this.brokers.forEach(function(b) { 90 this.brokers.forEach(function(b) {
38 if (b != from) { 91 if (b != from) {
39 b.brokeredClear(); 92 b.brokeredClear();
40 } 93 }
41 }); 94 });
42 } finally { 95 } finally {
43 this.dispatching = false; 96 this.dispatching = false;
44 } 97 }
45 } 98 }
46 } 99 }
OLDNEW
« no previous file with comments | « tools/turbolizer/selection.js ('k') | tools/turbolizer/text-view.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698