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

perf - use IdleValue for Collator creation to save ~25ms when starting without...

perf - use IdleValue for Collator creation to save ~25ms when starting without or with an empty explorer. fyi @bpasero
上级 e3f39ad4
......@@ -5,24 +5,23 @@
import * as strings from 'vs/base/common/strings';
import * as paths from 'vs/base/common/paths';
import { IdleValue } from 'vs/base/common/async';
let intlFileNameCollator: Intl.Collator;
let intlFileNameCollatorIsNumeric: boolean;
let intlFileNameCollator: IdleValue<{ collator: Intl.Collator, collatorIsNumeric: boolean }>;
export function setFileNameComparer(collator: Intl.Collator): void {
export function setFileNameComparer(collator: IdleValue<{ collator: Intl.Collator, collatorIsNumeric: boolean }>): void {
intlFileNameCollator = collator;
intlFileNameCollatorIsNumeric = collator.resolvedOptions().numeric;
}
export function compareFileNames(one: string, other: string, caseSensitive = false): number {
if (intlFileNameCollator) {
const a = one || '';
const b = other || '';
const result = intlFileNameCollator.compare(a, b);
const result = intlFileNameCollator.getValue().collator.compare(a, b);
// Using the numeric option in the collator will
// make compare(`foo1`, `foo01`) === 0. We must disambiguate.
if (intlFileNameCollatorIsNumeric && result === 0 && a !== b) {
if (intlFileNameCollator.getValue().collatorIsNumeric && result === 0 && a !== b) {
return a < b ? -1 : 1;
}
......@@ -59,19 +58,19 @@ export function compareFileExtensions(one: string, other: string): number {
const [oneName, oneExtension] = extractNameAndExtension(one);
const [otherName, otherExtension] = extractNameAndExtension(other);
let result = intlFileNameCollator.compare(oneExtension, otherExtension);
let result = intlFileNameCollator.getValue().collator.compare(oneExtension, otherExtension);
if (result === 0) {
// Using the numeric option in the collator will
// make compare(`foo1`, `foo01`) === 0. We must disambiguate.
if (intlFileNameCollatorIsNumeric && oneExtension !== otherExtension) {
if (intlFileNameCollator.getValue().collatorIsNumeric && oneExtension !== otherExtension) {
return oneExtension < otherExtension ? -1 : 1;
}
// Extensions are equal, compare filenames
result = intlFileNameCollator.compare(oneName, otherName);
result = intlFileNameCollator.getValue().collator.compare(oneName, otherName);
if (intlFileNameCollatorIsNumeric && result === 0 && oneName !== otherName) {
if (intlFileNameCollator.getValue().collatorIsNumeric && result === 0 && oneName !== otherName) {
return oneName < otherName ? -1 : 1;
}
}
......@@ -194,4 +193,4 @@ export function compareByPrefix(one: string, other: string, lookFor: string): nu
}
return 0;
}
\ No newline at end of file
}
......@@ -49,6 +49,7 @@ import { createHash } from 'crypto';
import { parseStorage, StorageObject } from 'vs/platform/storage/common/storageLegacyMigration';
import { StorageScope } from 'vs/platform/storage/common/storage';
import { endsWith } from 'vs/base/common/strings';
import { IdleValue } from 'vs/base/common/async';
gracefulFs.gracefulify(fs); // enable gracefulFs
......@@ -70,7 +71,13 @@ export function startup(configuration: IWindowConfiguration): Promise<void> {
KeyboardMapperFactory.INSTANCE._onKeyboardLayoutChanged();
// Setup Intl for comparers
comparer.setFileNameComparer(new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }));
comparer.setFileNameComparer(new IdleValue(() => {
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
return {
collator: collator,
collatorIsNumeric: collator.resolvedOptions().numeric
};
}));
// Open workbench
return openWorkbench(configuration);
......@@ -463,4 +470,4 @@ function createMainProcessServices(mainProcessClient: ElectronIPCClient, configu
serviceCollection.set(IWorkspacesService, new WorkspacesChannelClient(workspacesChannel));
return serviceCollection;
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册