Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions src/server/scriptVersionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,29 +524,18 @@ namespace ts.server {
}

private static buildTreeFromBottom(nodes: LineCollection[]): LineNode {
const interiorNodeCount = Math.ceil(nodes.length / lineCollectionCapacity);
const interiorNodes: LineNode[] = new Array(interiorNodeCount);
if (nodes.length < lineCollectionCapacity) {
return new LineNode(nodes);
}

const interiorNodes = new Array<LineNode>(Math.ceil(nodes.length / lineCollectionCapacity));
let nodeIndex = 0;
for (let i = 0; i < interiorNodeCount; i++) {
const interiorNode = interiorNodes[i] = new LineNode();
let charCount = 0;
let lineCount = 0;
for (let i = 0; i < interiorNodes.length; i++) {
const end = Math.min(nodeIndex + lineCollectionCapacity, nodes.length);
for (; nodeIndex < end; nodeIndex++) {
const node = nodes[nodeIndex];
interiorNode.add(node);
charCount += node.charCount();
lineCount += node.lineCount();
}
interiorNode.totalChars = charCount;
interiorNode.totalLines = lineCount;
}
if (interiorNodes.length === 1) {
return interiorNodes[0];
}
else {
return this.buildTreeFromBottom(interiorNodes);
interiorNodes[i] = new LineNode(nodes.slice(nodeIndex, end));
nodeIndex = end;
}
return this.buildTreeFromBottom(interiorNodes);
}

static linesFromText(text: string) {
Expand Down Expand Up @@ -575,7 +564,10 @@ namespace ts.server {
export class LineNode implements LineCollection {
totalChars = 0;
totalLines = 0;
private children: LineCollection[] = [];

constructor(private readonly children: LineCollection[] = []) {
if (children.length) this.updateCounts();
}

isLeaf() {
return false;
Expand Down