提交 6d7d9d99 编写于 作者: B Benjamin Pasero

perf - uri.toJSON() over toString() (fixes #18215)

上级 961ff966
......@@ -378,25 +378,36 @@ export default class URI {
}
public toJSON(): any {
return <UriState>{
const res = <UriState>{
scheme: this.scheme,
authority: this.authority,
path: this.path,
fsPath: this.fsPath,
query: this.query,
fragment: this.fragment,
external: this.toString(),
$mid: 1
};
if (this.authority) {
res.authority = this.authority;
}
if (this.query) {
res.query = this.query;
}
if (this.fragment) {
res.fragment = this.fragment;
}
return res;
}
static revive(data: any): URI {
let result = new URI();
result._scheme = (<UriState>data).scheme;
result._authority = (<UriState>data).authority;
result._authority = (<UriState>data).authority || URI._empty;
result._path = (<UriState>data).path;
result._query = (<UriState>data).query;
result._fragment = (<UriState>data).fragment;
result._query = (<UriState>data).query || URI._empty;
result._fragment = (<UriState>data).fragment || URI._empty;
result._fsPath = (<UriState>data).fsPath;
result._formatted = (<UriState>data).external;
URI._validate(result);
......
......@@ -95,7 +95,7 @@ Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditor(
);
interface ISerializedUntitledEditorInput {
resource: string;
resource: any | string; // TODO@Ben migration
modeId: string;
}
......@@ -120,7 +120,7 @@ class UntitledEditorInputFactory implements IEditorInputFactory {
resource = URI.file(resource.fsPath); // untitled with associated file path use the file schema
}
const serialized: ISerializedUntitledEditorInput = { resource: resource.toString(), modeId: untitledEditorInput.getModeId() };
const serialized: ISerializedUntitledEditorInput = { resource: resource.toJSON(), modeId: untitledEditorInput.getModeId() };
return JSON.stringify(serialized);
}
......@@ -128,7 +128,7 @@ class UntitledEditorInputFactory implements IEditorInputFactory {
public deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): EditorInput {
const deserialized: ISerializedUntitledEditorInput = JSON.parse(serializedEditorInput);
return this.untitledEditorService.createOrGet(URI.parse(deserialized.resource), deserialized.modeId);
return this.untitledEditorService.createOrGet(typeof deserialized.resource === 'string' ? URI.parse(deserialized.resource) : URI.revive(deserialized.resource), deserialized.modeId);
}
}
......
......@@ -105,7 +105,7 @@ const descriptor = new AsyncDescriptor<IFileEditorInput>('vs/workbench/parts/fil
Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerDefaultFileInput(descriptor);
interface ISerializedFileInput {
resource: string;
resource: any | string; // TODO@Ben migration
encoding?: string;
}
......@@ -133,7 +133,7 @@ class FileEditorInputFactory implements IEditorInputFactory {
const fileEditorInput = <FileEditorInput>editorInput;
const fileInput: ISerializedFileInput = {
resource: fileEditorInput.getResource().toString()
resource: fileEditorInput.getResource().toJSON()
};
const encoding = fileEditorInput.getPreferredEncoding();
......@@ -147,7 +147,7 @@ class FileEditorInputFactory implements IEditorInputFactory {
public deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): EditorInput {
const fileInput: ISerializedFileInput = JSON.parse(serializedEditorInput);
return instantiationService.createInstance(FileEditorInput, URI.parse(fileInput.resource), fileInput.encoding);
return instantiationService.createInstance(FileEditorInput, typeof fileInput.resource === 'string' ? URI.parse(fileInput.resource) : URI.revive(fileInput.resource), fileInput.encoding);
}
}
......
......@@ -56,26 +56,17 @@ export class ChokidarWatcherService implements IWatcherService {
// Change
if (type === 'change') {
event = {
type: 0,
path: path
};
event = { type: 0, path };
}
// Add
else if (type === 'add' || type === 'addDir') {
event = {
type: 1,
path: path
};
event = { type: 1, path };
}
// Delete
else if (type === 'unlink' || type === 'unlinkDir') {
event = {
type: 2,
path: path
};
event = { type: 2, path };
}
if (event) {
......
......@@ -71,7 +71,7 @@ export class EditorState {
}
interface ISerializedFileHistoryEntry {
resource: string;
resource: any | string; // TODO@Ben migration
}
export abstract class BaseHistoryService {
......@@ -708,7 +708,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
return void 0; // only file resource inputs are serializable currently
}
return { resource: (input as IResourceInput).resource.toString() };
return { resource: (input as IResourceInput).resource.toJSON() };
}).filter(serialized => !!serialized);
this.storageService.store(HistoryService.STORAGE_KEY, JSON.stringify(entries), StorageScope.WORKSPACE);
......@@ -725,7 +725,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
this.history = entries.map(entry => {
const serializedFileInput = entry as ISerializedFileHistoryEntry;
if (serializedFileInput.resource) {
return { resource: URI.parse(serializedFileInput.resource) } as IResourceInput;
return { resource: typeof serializedFileInput.resource === 'string' ? URI.parse(serializedFileInput.resource) : URI.revive(serializedFileInput.resource) } as IResourceInput;
}
return void 0;
......
......@@ -25,11 +25,8 @@ suite('ExtHostTypes', function () {
assert.deepEqual(data, {
$mid: 1,
scheme: 'file',
authority: '',
path: '/path/test.file',
fsPath: '/path/test.file'.replace(/\//g, isWindows ? '\\' : '/'),
query: '',
fragment: '',
external: 'file:///path/test.file'
});
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册