diff --git a/src/vs/editor/common/services/editorSimpleWorker.ts b/src/vs/editor/common/services/editorSimpleWorker.ts index 4ad0c9d316b..e5e93423f69 100644 --- a/src/vs/editor/common/services/editorSimpleWorker.ts +++ b/src/vs/editor/common/services/editorSimpleWorker.ts @@ -235,7 +235,7 @@ class MirrorModel extends BaseMirrorModel implements ICommonModel { public offsetAt(position: IPosition): number { position = this._validatePosition(position); this._ensureLineStarts(); - return this._lineStarts!.getAccumulatedValue(position.lineNumber - 2) + (position.column - 1); + return this._lineStarts!.getPrefixSum(position.lineNumber - 2) + (position.column - 1); } public positionAt(offset: number): IPosition { diff --git a/src/vs/editor/common/viewModel/prefixSumComputer.ts b/src/vs/editor/common/viewModel/prefixSumComputer.ts index 6cb1312c07e..952a810a9d0 100644 --- a/src/vs/editor/common/viewModel/prefixSumComputer.ts +++ b/src/vs/editor/common/viewModel/prefixSumComputer.ts @@ -85,9 +85,9 @@ export class PrefixSumComputer { return true; } - public removeValues(startIndex: number, cnt: number): boolean { + public removeValues(startIndex: number, count: number): boolean { startIndex = toUint32(startIndex); - cnt = toUint32(cnt); + count = toUint32(count); const oldValues = this.values; const oldPrefixSum = this.prefixSum; @@ -96,18 +96,18 @@ export class PrefixSumComputer { return false; } - let maxCnt = oldValues.length - startIndex; - if (cnt >= maxCnt) { - cnt = maxCnt; + let maxCount = oldValues.length - startIndex; + if (count >= maxCount) { + count = maxCount; } - if (cnt === 0) { + if (count === 0) { return false; } - this.values = new Uint32Array(oldValues.length - cnt); + this.values = new Uint32Array(oldValues.length - count); this.values.set(oldValues.subarray(0, startIndex), 0); - this.values.set(oldValues.subarray(startIndex + cnt), startIndex); + this.values.set(oldValues.subarray(startIndex + count), startIndex); this.prefixSum = new Uint32Array(this.values.length); if (startIndex - 1 < this.prefixSumValidIndex[0]) { @@ -119,23 +119,23 @@ export class PrefixSumComputer { return true; } - public getTotalValue(): number { + public getTotalSum(): number { if (this.values.length === 0) { return 0; } - return this._getAccumulatedValue(this.values.length - 1); + return this._getPrefixSum(this.values.length - 1); } - public getAccumulatedValue(index: number): number { + public getPrefixSum(index: number): number { if (index < 0) { return 0; } index = toUint32(index); - return this._getAccumulatedValue(index); + return this._getPrefixSum(index); } - private _getAccumulatedValue(index: number): number { + private _getPrefixSum(index: number): number { if (index <= this.prefixSumValidIndex[0]) { return this.prefixSum[index]; } @@ -157,11 +157,11 @@ export class PrefixSumComputer { return this.prefixSum[index]; } - public getIndexOf(accumulatedValue: number): PrefixSumIndexOfResult { - accumulatedValue = Math.floor(accumulatedValue); //@perf + public getIndexOf(sum: number): PrefixSumIndexOfResult { + sum = Math.floor(sum); //@perf // Compute all sums (to get a fully valid prefixSum) - this.getTotalValue(); + this.getTotalSum(); let low = 0; let high = this.values.length - 1; @@ -175,15 +175,15 @@ export class PrefixSumComputer { midStop = this.prefixSum[mid]; midStart = midStop - this.values[mid]; - if (accumulatedValue < midStart) { + if (sum < midStart) { high = mid - 1; - } else if (accumulatedValue >= midStop) { + } else if (sum >= midStop) { low = mid + 1; } else { break; } } - return new PrefixSumIndexOfResult(mid, accumulatedValue - midStart); + return new PrefixSumIndexOfResult(mid, sum - midStart); } } diff --git a/src/vs/editor/test/common/viewModel/prefixSumComputer.test.ts b/src/vs/editor/test/common/viewModel/prefixSumComputer.test.ts index 80df1a94eb2..0ac5ed2672d 100644 --- a/src/vs/editor/test/common/viewModel/prefixSumComputer.test.ts +++ b/src/vs/editor/test/common/viewModel/prefixSumComputer.test.ts @@ -22,13 +22,13 @@ suite('Editor ViewModel - PrefixSumComputer', () => { let indexOfResult: PrefixSumIndexOfResult; let psc = new PrefixSumComputer(toUint32Array([1, 1, 2, 1, 3])); - assert.strictEqual(psc.getTotalValue(), 8); - assert.strictEqual(psc.getAccumulatedValue(-1), 0); - assert.strictEqual(psc.getAccumulatedValue(0), 1); - assert.strictEqual(psc.getAccumulatedValue(1), 2); - assert.strictEqual(psc.getAccumulatedValue(2), 4); - assert.strictEqual(psc.getAccumulatedValue(3), 5); - assert.strictEqual(psc.getAccumulatedValue(4), 8); + assert.strictEqual(psc.getTotalSum(), 8); + assert.strictEqual(psc.getPrefixSum(-1), 0); + assert.strictEqual(psc.getPrefixSum(0), 1); + assert.strictEqual(psc.getPrefixSum(1), 2); + assert.strictEqual(psc.getPrefixSum(2), 4); + assert.strictEqual(psc.getPrefixSum(3), 5); + assert.strictEqual(psc.getPrefixSum(4), 8); indexOfResult = psc.getIndexOf(0); assert.strictEqual(indexOfResult.index, 0); assert.strictEqual(indexOfResult.remainder, 0); @@ -59,21 +59,21 @@ suite('Editor ViewModel - PrefixSumComputer', () => { // [1, 2, 2, 1, 3] psc.changeValue(1, 2); - assert.strictEqual(psc.getTotalValue(), 9); - assert.strictEqual(psc.getAccumulatedValue(0), 1); - assert.strictEqual(psc.getAccumulatedValue(1), 3); - assert.strictEqual(psc.getAccumulatedValue(2), 5); - assert.strictEqual(psc.getAccumulatedValue(3), 6); - assert.strictEqual(psc.getAccumulatedValue(4), 9); + assert.strictEqual(psc.getTotalSum(), 9); + assert.strictEqual(psc.getPrefixSum(0), 1); + assert.strictEqual(psc.getPrefixSum(1), 3); + assert.strictEqual(psc.getPrefixSum(2), 5); + assert.strictEqual(psc.getPrefixSum(3), 6); + assert.strictEqual(psc.getPrefixSum(4), 9); // [1, 0, 2, 1, 3] psc.changeValue(1, 0); - assert.strictEqual(psc.getTotalValue(), 7); - assert.strictEqual(psc.getAccumulatedValue(0), 1); - assert.strictEqual(psc.getAccumulatedValue(1), 1); - assert.strictEqual(psc.getAccumulatedValue(2), 3); - assert.strictEqual(psc.getAccumulatedValue(3), 4); - assert.strictEqual(psc.getAccumulatedValue(4), 7); + assert.strictEqual(psc.getTotalSum(), 7); + assert.strictEqual(psc.getPrefixSum(0), 1); + assert.strictEqual(psc.getPrefixSum(1), 1); + assert.strictEqual(psc.getPrefixSum(2), 3); + assert.strictEqual(psc.getPrefixSum(3), 4); + assert.strictEqual(psc.getPrefixSum(4), 7); indexOfResult = psc.getIndexOf(0); assert.strictEqual(indexOfResult.index, 0); assert.strictEqual(indexOfResult.remainder, 0); @@ -101,12 +101,12 @@ suite('Editor ViewModel - PrefixSumComputer', () => { // [1, 0, 0, 1, 3] psc.changeValue(2, 0); - assert.strictEqual(psc.getTotalValue(), 5); - assert.strictEqual(psc.getAccumulatedValue(0), 1); - assert.strictEqual(psc.getAccumulatedValue(1), 1); - assert.strictEqual(psc.getAccumulatedValue(2), 1); - assert.strictEqual(psc.getAccumulatedValue(3), 2); - assert.strictEqual(psc.getAccumulatedValue(4), 5); + assert.strictEqual(psc.getTotalSum(), 5); + assert.strictEqual(psc.getPrefixSum(0), 1); + assert.strictEqual(psc.getPrefixSum(1), 1); + assert.strictEqual(psc.getPrefixSum(2), 1); + assert.strictEqual(psc.getPrefixSum(3), 2); + assert.strictEqual(psc.getPrefixSum(4), 5); indexOfResult = psc.getIndexOf(0); assert.strictEqual(indexOfResult.index, 0); assert.strictEqual(indexOfResult.remainder, 0); @@ -128,12 +128,12 @@ suite('Editor ViewModel - PrefixSumComputer', () => { // [1, 0, 0, 0, 3] psc.changeValue(3, 0); - assert.strictEqual(psc.getTotalValue(), 4); - assert.strictEqual(psc.getAccumulatedValue(0), 1); - assert.strictEqual(psc.getAccumulatedValue(1), 1); - assert.strictEqual(psc.getAccumulatedValue(2), 1); - assert.strictEqual(psc.getAccumulatedValue(3), 1); - assert.strictEqual(psc.getAccumulatedValue(4), 4); + assert.strictEqual(psc.getTotalSum(), 4); + assert.strictEqual(psc.getPrefixSum(0), 1); + assert.strictEqual(psc.getPrefixSum(1), 1); + assert.strictEqual(psc.getPrefixSum(2), 1); + assert.strictEqual(psc.getPrefixSum(3), 1); + assert.strictEqual(psc.getPrefixSum(4), 4); indexOfResult = psc.getIndexOf(0); assert.strictEqual(indexOfResult.index, 0); assert.strictEqual(indexOfResult.remainder, 0); @@ -154,12 +154,12 @@ suite('Editor ViewModel - PrefixSumComputer', () => { psc.changeValue(1, 1); psc.changeValue(3, 1); psc.changeValue(4, 1); - assert.strictEqual(psc.getTotalValue(), 4); - assert.strictEqual(psc.getAccumulatedValue(0), 1); - assert.strictEqual(psc.getAccumulatedValue(1), 2); - assert.strictEqual(psc.getAccumulatedValue(2), 2); - assert.strictEqual(psc.getAccumulatedValue(3), 3); - assert.strictEqual(psc.getAccumulatedValue(4), 4); + assert.strictEqual(psc.getTotalSum(), 4); + assert.strictEqual(psc.getPrefixSum(0), 1); + assert.strictEqual(psc.getPrefixSum(1), 2); + assert.strictEqual(psc.getPrefixSum(2), 2); + assert.strictEqual(psc.getPrefixSum(3), 3); + assert.strictEqual(psc.getPrefixSum(4), 4); indexOfResult = psc.getIndexOf(0); assert.strictEqual(indexOfResult.index, 0); assert.strictEqual(indexOfResult.remainder, 0); diff --git a/src/vs/workbench/api/common/extHostDocumentData.ts b/src/vs/workbench/api/common/extHostDocumentData.ts index d244a16b8aa..78e12d7a47c 100644 --- a/src/vs/workbench/api/common/extHostDocumentData.ts +++ b/src/vs/workbench/api/common/extHostDocumentData.ts @@ -143,7 +143,7 @@ export class ExtHostDocumentData extends MirrorTextModel { private _offsetAt(position: vscode.Position): number { position = this._validatePosition(position); this._ensureLineStarts(); - return this._lineStarts!.getAccumulatedValue(position.line - 1) + position.character; + return this._lineStarts!.getPrefixSum(position.line - 1) + position.character; } private _positionAt(offset: number): vscode.Position { diff --git a/src/vs/workbench/api/common/extHostNotebookConcatDocument.ts b/src/vs/workbench/api/common/extHostNotebookConcatDocument.ts index 215975bdfd2..d25c8dfe06d 100644 --- a/src/vs/workbench/api/common/extHostNotebookConcatDocument.ts +++ b/src/vs/workbench/api/common/extHostNotebookConcatDocument.ts @@ -123,7 +123,7 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD offsetAt(position: vscode.Position): number { const idx = this._cellLines.getIndexOf(position.line); - const offset1 = this._cellLengths.getAccumulatedValue(idx.index - 1); + const offset1 = this._cellLengths.getPrefixSum(idx.index - 1); const offset2 = this._cells[idx.index].document.offsetAt(position.with(idx.remainder)); return offset1 + offset2; } @@ -131,13 +131,13 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD positionAt(locationOrOffset: vscode.Location | number): vscode.Position { if (typeof locationOrOffset === 'number') { const idx = this._cellLengths.getIndexOf(locationOrOffset); - const lineCount = this._cellLines.getAccumulatedValue(idx.index - 1); + const lineCount = this._cellLines.getPrefixSum(idx.index - 1); return this._cells[idx.index].document.positionAt(idx.remainder).translate(lineCount); } const idx = this._cellUris.get(locationOrOffset.uri); if (idx !== undefined) { - const line = this._cellLines.getAccumulatedValue(idx - 1); + const line = this._cellLines.getPrefixSum(idx - 1); return new types.Position(line + locationOrOffset.range.start.line, locationOrOffset.range.start.character); } // do better? @@ -180,7 +180,7 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD const cellPosition = new types.Position(startIdx.remainder, position.character); const validCellPosition = this._cells[startIdx.index].document.validatePosition(cellPosition); - const line = this._cellLines.getAccumulatedValue(startIdx.index - 1); + const line = this._cellLines.getPrefixSum(startIdx.index - 1); return new types.Position(line + validCellPosition.line, validCellPosition.character); } } diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/find/findModel.ts b/src/vs/workbench/contrib/notebook/browser/contrib/find/findModel.ts index 3e6d07b7822..99da66dff8e 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/find/findModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/find/findModel.ts @@ -88,7 +88,7 @@ export class FindModel extends Disposable { } else { // const currIndex = this._findMatchesStarts!.getIndexOf(this._currentMatch); // currCell = this._findMatches[currIndex.index].cell; - const totalVal = this._findMatchesStarts.getTotalValue(); + const totalVal = this._findMatchesStarts.getTotalSum(); if (this._currentMatch === -1) { this._currentMatch = previous ? totalVal - 1 : 0; } else { diff --git a/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.ts b/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.ts index 84ef80fbea3..bf8c441d9a5 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.ts @@ -111,7 +111,7 @@ export class DiffNestedCellViewModel extends Disposable implements IDiffNestedCe throw new Error('Output index out of range!'); } - return this._outputsTop!.getAccumulatedValue(index - 1); + return this._outputsTop!.getPrefixSum(index - 1); } updateOutputHeight(index: number, height: number): void { @@ -129,6 +129,6 @@ export class DiffNestedCellViewModel extends Disposable implements IDiffNestedCe getOutputTotalHeight() { this._ensureOutputsTop(); - return this._outputsTop?.getTotalValue() ?? 0; + return this._outputsTop?.getTotalSum() ?? 0; } } diff --git a/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts b/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts index 5584ff93977..2d7032b81a4 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts @@ -469,7 +469,7 @@ export class NotebookCellList extends WorkbenchList implements ID return viewIndex; } - const modelIndex = this.hiddenRangesPrefixSum.getAccumulatedValue(viewIndex - 1); + const modelIndex = this.hiddenRangesPrefixSum.getPrefixSum(viewIndex - 1); return modelIndex; } @@ -486,9 +486,9 @@ export class NotebookCellList extends WorkbenchList implements ID const viewIndexInfo = this.hiddenRangesPrefixSum.getIndexOf(modelIndex); if (viewIndexInfo.remainder !== 0) { - if (modelIndex >= this.hiddenRangesPrefixSum.getTotalValue()) { + if (modelIndex >= this.hiddenRangesPrefixSum.getTotalSum()) { // it's already after the last hidden range - return modelIndex - (this.hiddenRangesPrefixSum.getTotalValue() - this.hiddenRangesPrefixSum.getCount()); + return modelIndex - (this.hiddenRangesPrefixSum.getTotalSum() - this.hiddenRangesPrefixSum.getCount()); } return undefined; } else { @@ -504,7 +504,7 @@ export class NotebookCellList extends WorkbenchList implements ID let modelIndex = topModelIndex; while (index <= bottomViewIndex) { - const accu = this.hiddenRangesPrefixSum!.getAccumulatedValue(index); + const accu = this.hiddenRangesPrefixSum!.getPrefixSum(index); if (accu === modelIndex + 1) { // no hidden area after it if (stack.length) { @@ -575,8 +575,8 @@ export class NotebookCellList extends WorkbenchList implements ID const viewIndexInfo = this.hiddenRangesPrefixSum.getIndexOf(modelIndex); if (viewIndexInfo.remainder !== 0) { - if (modelIndex >= this.hiddenRangesPrefixSum.getTotalValue()) { - return modelIndex - (this.hiddenRangesPrefixSum.getTotalValue() - this.hiddenRangesPrefixSum.getCount()); + if (modelIndex >= this.hiddenRangesPrefixSum.getTotalSum()) { + return modelIndex - (this.hiddenRangesPrefixSum.getTotalSum() - this.hiddenRangesPrefixSum.getCount()); } } @@ -591,8 +591,8 @@ export class NotebookCellList extends WorkbenchList implements ID const viewIndexInfo = this.hiddenRangesPrefixSum.getIndexOf(modelIndex); if (viewIndexInfo.remainder !== 0) { - if (modelIndex >= this.hiddenRangesPrefixSum.getTotalValue()) { - return modelIndex - (this.hiddenRangesPrefixSum.getTotalValue() - this.hiddenRangesPrefixSum.getCount()); + if (modelIndex >= this.hiddenRangesPrefixSum.getTotalSum()) { + return modelIndex - (this.hiddenRangesPrefixSum.getTotalSum() - this.hiddenRangesPrefixSum.getCount()); } } diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts index c2673fa89ea..83d43339338 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts @@ -162,7 +162,7 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod const notebookLayoutConfiguration = this.viewContext.notebookOptions.getLayoutConfiguration(); const bottomToolbarDimensions = this.viewContext.notebookOptions.computeBottomToolbarDimensions(); const outputShowMoreContainerHeight = state.outputShowMoreContainerHeight ? state.outputShowMoreContainerHeight : this._layoutInfo.outputShowMoreContainerHeight; - let outputTotalHeight = Math.max(this._outputMinHeight, this.metadata.outputCollapsed ? notebookLayoutConfiguration.collapsedIndicatorHeight : this._outputsTop!.getTotalValue()); + let outputTotalHeight = Math.max(this._outputMinHeight, this.metadata.outputCollapsed ? notebookLayoutConfiguration.collapsedIndicatorHeight : this._outputsTop!.getTotalSum()); const originalLayout = this.layoutInfo; if (!this.metadata.inputCollapsed) { @@ -371,7 +371,7 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod throw new Error('Output index out of range!'); } - return this._outputsTop!.getAccumulatedValue(index - 1); + return this._outputsTop!.getPrefixSum(index - 1); } getOutputOffset(index: number): number {