Skip to content

Commit 71e2a85

Browse files
committed
Cache custom label lookups with MRU
1 parent 62e4388 commit 71e2a85

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/vs/workbench/services/editor/common/customEditorLabelService.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
1313
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
1414
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
1515
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
16+
import { MRUCache } from 'vs/base/common/map';
1617

1718
interface ICustomEditorLabelObject {
1819
readonly [key: string]: string;
@@ -39,6 +40,8 @@ export class CustomEditorLabelService extends Disposable implements ICustomEdito
3940
private patterns: ICustomEditorLabelPattern[] = [];
4041
private enabled = true;
4142

43+
private cache = new MRUCache<URI, string>(3);
44+
4245
constructor(
4346
@IConfigurationService private readonly configurationService: IConfigurationService,
4447
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
@@ -115,7 +118,18 @@ export class CustomEditorLabelService extends Disposable implements ICustomEdito
115118
if (!this.enabled) {
116119
return undefined;
117120
}
118-
return this.applyPatterns(resource);
121+
122+
const cached = this.cache.get(resource);
123+
if (cached !== undefined) {
124+
return cached;
125+
}
126+
127+
const result = this.applyPatterns(resource);
128+
if (result !== undefined) {
129+
this.cache.set(resource, result);
130+
}
131+
132+
return result;
119133
}
120134

121135
private applyPatterns(resource: URI): string | undefined {

0 commit comments

Comments
 (0)