提交 effd983f 编写于 作者: J Johannes Rieken

improve perf of findId and getElementById, #50575

上级 c5160aad
......@@ -13,6 +13,7 @@ import { IPosition } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { first, size } from 'vs/base/common/collections';
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
import { commonPrefixLength } from 'vs/base/common/strings';
export type FuzzyScore = [number, number[]];
......@@ -21,20 +22,38 @@ export abstract class TreeElement {
abstract children: { [id: string]: TreeElement };
abstract parent: TreeElement | any;
static findId(candidate: string, container: TreeElement): string {
static findId(candidate: SymbolInformation | string, container: TreeElement): string {
// complex id-computation which contains the origin/extension,
// the parent path, and some dedupe logic when names collide
let id = container.id + candidate;
for (let i = 1; container.children[id] !== void 0; i++) {
id = container.id + candidate + i;
let candidateId: string;
if (typeof candidate === 'string') {
candidateId = `${container.id}/${candidate}`;
} else {
candidateId = `${container.id}/${candidate.name}`;
if (container.children[candidateId] !== void 0) {
candidateId = `${container.id}/${candidate.name}_${candidate.definingRange.startLineNumber}_${candidate.definingRange.startColumn}`;
}
}
let id = candidateId;
for (let i = 0; container.children[id] !== void 0; i++) {
id = `${candidateId}_${i}`;
}
return id;
}
static getElementById(id: string, element: TreeElement): TreeElement {
if (element.id === id) {
if (!id) {
return undefined;
}
let len = commonPrefixLength(id, element.id);
if (len === id.length) {
return element;
}
if (len < element.id.length) {
return undefined;
}
for (const key in element.children) {
let candidate = TreeElement.getElementById(id, element.children[key]);
if (candidate) {
......@@ -174,7 +193,7 @@ export class OutlineModel extends TreeElement {
}
private static _makeOutlineElement(info: SymbolInformation, container: OutlineGroup | OutlineElement): void {
let id = TreeElement.findId(info.name, container);
let id = TreeElement.findId(info, container);
let res = new OutlineElement(id, container, info);
if (info.children) {
for (const childInfo of info.children) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册