Skip to content

Commit 8a8fb8d

Browse files
author
aiday-mar
committed
Using binary search in the function getCandidateStickyLinesIntersectingFromOutline to improve performance
1 parent 0a532a4 commit 8a8fb8d

File tree

1 file changed

+7
-32
lines changed

1 file changed

+7
-32
lines changed

src/vs/editor/contrib/stickyScroll/browser/stickyScrollProvider.ts

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -97,49 +97,28 @@ export class StickyLineCandidateProvider extends Disposable {
9797
}
9898
}
9999

100-
private changeIndex(index: number) {
100+
private updatedIndex(index: number) {
101101
if (index === -1) {
102102
index = 0;
103103
} else if (index < 0) {
104104
index = -index - 2;
105105
}
106106
return index;
107107
}
108+
108109
public getCandidateStickyLinesIntersectingFromOutline(range: StickyRange, outlineModel: StickyOutlineElement, result: StickyLineCandidate[], depth: number, lastStartLineNumber: number): void {
110+
if (outlineModel.children.length === 0) {
111+
return;
112+
}
109113
let lastLine = lastStartLineNumber;
110-
// Find largest number in the start lines being smaller than the current range start line
111114
const childrenStartLines = outlineModel.children.map(child => child.range?.startLineNumber as number);
112115
let indexLower = binarySearch(childrenStartLines, range.startLineNumber, (a: number, b: number) => { return a - b; });
113116
let indexUpper = binarySearch(childrenStartLines, range.startLineNumber + depth, (a: number, b: number) => { return a - b; });
114-
console.log('children start lines : ', childrenStartLines);
115-
console.log('range start line number : ', range.startLineNumber);
116-
console.log('range.startLineNumber + depth : ', range.startLineNumber + depth);
117-
console.log('index lower before change : ', indexLower);
118-
console.log('index upper before change : ', indexUpper);
119-
120-
indexLower = this.changeIndex(indexLower);
121-
indexUpper = this.changeIndex(indexUpper);
122-
123-
console.log('indexLower : ', indexLower);
124-
console.log('indexUpper : ', indexUpper);
117+
indexLower = this.updatedIndex(indexLower);
118+
indexUpper = this.updatedIndex(indexUpper);
125119

126120
for (let i = indexLower; i <= indexUpper; i++) {
127-
console.log('currently at index : ', i);
128121
const child = outlineModel.children[i];
129-
if (child && child.range) {
130-
const childStartLine = child.range.startLineNumber;
131-
const childEndLine = child.range.endLineNumber;
132-
if (range.startLineNumber <= childEndLine + 1 && childStartLine - 1 <= range.endLineNumber && childStartLine !== lastLine) {
133-
lastLine = childStartLine;
134-
result.push(new StickyLineCandidate(childStartLine, childEndLine - 1, depth + 1));
135-
this.getCandidateStickyLinesIntersectingFromOutline(range, child, result, depth + 1, childStartLine);
136-
}
137-
} else {
138-
this.getCandidateStickyLinesIntersectingFromOutline(range, child, result, depth, lastStartLineNumber);
139-
}
140-
}
141-
/*
142-
for (const child of outlineModel.children) {
143122
if (child.range) {
144123
const childStartLine = child.range.startLineNumber;
145124
const childEndLine = child.range.endLineNumber;
@@ -152,15 +131,11 @@ export class StickyLineCandidateProvider extends Disposable {
152131
this.getCandidateStickyLinesIntersectingFromOutline(range, child, result, depth, lastStartLineNumber);
153132
}
154133
}
155-
*/
156134
}
157135

158136
public getCandidateStickyLinesIntersecting(range: StickyRange): StickyLineCandidate[] {
159137
let stickyLineCandidates: StickyLineCandidate[] = [];
160-
console.log('this._outlineModel : ', this._outlineModel);
161-
console.log('range : ', range);
162138
this.getCandidateStickyLinesIntersectingFromOutline(range, this._outlineModel as StickyOutlineElement, stickyLineCandidates, 0, -1);
163-
console.log('stickyLineCandidates : ', stickyLineCandidates);
164139
const hiddenRanges: Range[] | undefined = this._editor._getViewModel()?.getHiddenAreas();
165140
if (hiddenRanges) {
166141
for (const hiddenRange of hiddenRanges) {

0 commit comments

Comments
 (0)