diff options
Diffstat (limited to 'deps/v8/tools/turbolizer/selection.js')
-rw-r--r-- | deps/v8/tools/turbolizer/selection.js | 130 |
1 files changed, 41 insertions, 89 deletions
diff --git a/deps/v8/tools/turbolizer/selection.js b/deps/v8/tools/turbolizer/selection.js index 26f1bde197..9bd937c84a 100644 --- a/deps/v8/tools/turbolizer/selection.js +++ b/deps/v8/tools/turbolizer/selection.js @@ -2,107 +2,59 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -var Selection = function(handler) { - this.handler = handler; - this.selectionBase = null; - this.lastSelection = null; - this.selection = new Set(); -} - - -Selection.prototype.isEmpty = function() { - return this.selection.size == 0; -} - - -Selection.prototype.clear = function() { - var handler = this.handler; - this.selectionBase = null; - this.lastSelection = null; - handler.select(this.selection, false); - handler.clear(); - this.selection = new Set(); -} +class Selection { + constructor(stringKeyFnc) { + this.selection = new Map(); + this.stringKey = stringKeyFnc; + } + isEmpty() { + return this.selection.size == 0; + } -count = 0; + clear() { + this.selection = new Map(); + } -Selection.prototype.select = function(s, isSelected) { - var handler = this.handler; - if (!(Symbol.iterator in Object(s))) { s = [s]; } - if (isSelected) { - let first = true; - for (let i of s) { - if (first) { - this.selectionBase = i; - this.lastSelection = i; - first = false; + select(s, isSelected) { + if (!isIterable(s)) { s = [s]; } + for (const i of s) { + if (!i) continue; + if (isSelected == undefined) { + isSelected = !this.selection.has(this.stringKey(i)); } - this.selection.add(i); - } - handler.select(this.selection, true); - } else { - let unselectSet = new Set(); - for (let i of s) { - if (this.selection.has(i)) { - unselectSet.add(i); - this.selection.delete(i); + if (isSelected) { + this.selection.set(this.stringKey(i), i); + } else { + this.selection.delete(this.stringKey(i)); } } - handler.select(unselectSet, false); } -} + isSelected(i) { + return this.selection.has(this.stringKey(i)); + } -Selection.prototype.extendTo = function(pos) { - if (pos == this.lastSelection || this.lastSelection === null) return; + isKeySelected(key) { + return this.selection.has(key); + } - var handler = this.handler; - var pos_diff = handler.selectionDifference(pos, true, this.lastSelection, false); - var unselect_diff = []; - if (pos_diff.length == 0) { - pos_diff = handler.selectionDifference(this.selectionBase, false, pos, true); - if (pos_diff.length != 0) { - unselect_diff = handler.selectionDifference(this.lastSelection, true, this.selectionBase, false); - this.selection = new Set(); - this.selection.add(this.selectionBase); - for (var d of pos_diff) { - this.selection.add(d); - } - } else { - unselect_diff = handler.selectionDifference(this.lastSelection, true, pos, false); - for (var d of unselect_diff) { - this.selection.delete(d); - } - } - } else { - unselect_diff = handler.selectionDifference(this.selectionBase, false, this.lastSelection, true); - if (unselect_diff != 0) { - pos_diff = handler.selectionDifference(pos, true, this.selectionBase, false); - if (pos_diff.length == 0) { - unselect_diff = handler.selectionDifference(pos, false, this.lastSelection, true); - } - for (var d of unselect_diff) { - this.selection.delete(d); - } - } - if (pos_diff.length != 0) { - for (var d of pos_diff) { - this.selection.add(d); - } + selectedKeys() { + var result = new Set(); + for (var i of this.selection.keys()) { + result.add(i); } + return result; } - handler.select(unselect_diff, false); - handler.select(pos_diff, true); - this.lastSelection = pos; -} - -Selection.prototype.detachSelection = function() { - var result = new Set(); - for (var i of this.selection) { - result.add(i); + detachSelection() { + var result = new Set(); + for (var i of this.selection.keys()) { + result.add(i); + } + this.clear(); + return result; } - this.clear(); - return result; + + [Symbol.iterator]() { return this.selection.values() } } |