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

when capping decoration events pick somewhat smarter,...

when capping decoration events pick somewhat smarter, https://github.com/microsoft/vscode/issues/108292
上级 4cc712b9
......@@ -55,6 +55,20 @@ export function escapeRegExpCharacters(value: string): string {
return value.replace(/[\\\{\}\*\+\?\|\^\$\.\[\]\(\)]/g, '\\$&');
}
/**
* Counts how often `character` occurs inside `value`.
*/
export function count(value: string, character: string): number {
let result = 0;
const ch = character.charCodeAt(0);
for (let i = value.length - 1; i >= 0; i--) {
if (value.charCodeAt(i) === ch) {
result++;
}
}
return result;
}
/**
* Removes all occurrences of needle from the beginning and end of haystack.
* @param haystack string to trim
......
......@@ -12,7 +12,9 @@ import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
import { ILogService } from 'vs/platform/log/common/log';
import { asArray } from 'vs/base/common/arrays';
import { asArray, groupBy } from 'vs/base/common/arrays';
import { count } from 'vs/base/common/strings';
import { dirname } from 'vs/base/common/path';
interface ProviderData {
provider: vscode.FileDecorationProvider;
......@@ -22,6 +24,7 @@ interface ProviderData {
export class ExtHostDecorations implements ExtHostDecorationsShape {
private static _handlePool = 0;
private static _maxEventSize = 250;
readonly _serviceBrand: undefined;
private readonly _provider = new Map<number, ProviderData>();
......@@ -40,9 +43,34 @@ export class ExtHostDecorations implements ExtHostDecorationsShape {
this._proxy.$registerDecorationProvider(handle, extensionId.value);
const listener = provider.onDidChange(e => {
this._proxy.$onDidChange(handle, !e || (Array.isArray(e) && e.length > 250)
? null
: asArray(e));
if (!e) {
this._proxy.$onDidChange(handle, null);
return;
}
let array = asArray(e);
if (array.length <= ExtHostDecorations._maxEventSize) {
this._proxy.$onDidChange(handle, array);
return;
}
// too many resources per event. pick one resource per folder, starting
// with parent folders
const mapped = array.map(uri => ({ uri, rank: count(uri.path, '/') }));
const groups = groupBy(mapped, (a, b) => a.rank - b.rank);
let picked: URI[] = [];
outer: for (let uris of groups) {
let lastDirname: string | undefined;
for (let obj of uris) {
let myDirname = dirname(obj.uri.path);
if (lastDirname !== myDirname) {
lastDirname = myDirname;
if (picked.push(obj.uri) >= ExtHostDecorations._maxEventSize) {
break outer;
}
}
}
}
this._proxy.$onDidChange(handle, picked);
});
return new Disposable(() => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册