Replacing object map with true map

This commit is contained in:
Matt Bierner 2019-07-01 17:29:59 -07:00
parent 4727c9a045
commit 612901a9e9
2 changed files with 10 additions and 11 deletions

View file

@ -17,18 +17,17 @@ import { ITheme, IThemeService, ThemeColor } from 'vs/platform/theme/common/them
export abstract class CodeEditorServiceImpl extends AbstractCodeEditorService {
private readonly _styleSheet: HTMLStyleElement;
private readonly _decorationOptionProviders: { [key: string]: IModelDecorationOptionsProvider };
private readonly _decorationOptionProviders = new Map<string, IModelDecorationOptionsProvider>();
private readonly _themeService: IThemeService;
constructor(@IThemeService themeService: IThemeService, styleSheet = dom.createStyleSheet()) {
super();
this._styleSheet = styleSheet;
this._decorationOptionProviders = Object.create(null);
this._themeService = themeService;
}
public registerDecorationType(key: string, options: IDecorationRenderOptions, parentTypeKey?: string): void {
let provider = this._decorationOptionProviders[key];
let provider = this._decorationOptionProviders.get(key);
if (!provider) {
const providerArgs: ProviderArguments = {
styleSheet: this._styleSheet,
@ -41,17 +40,17 @@ export abstract class CodeEditorServiceImpl extends AbstractCodeEditorService {
} else {
provider = new DecorationSubTypeOptionsProvider(this._themeService, providerArgs);
}
this._decorationOptionProviders[key] = provider;
this._decorationOptionProviders.set(key, provider);
}
provider.refCount++;
}
public removeDecorationType(key: string): void {
const provider = this._decorationOptionProviders[key];
const provider = this._decorationOptionProviders.get(key);
if (provider) {
provider.refCount--;
if (provider.refCount <= 0) {
delete this._decorationOptionProviders[key];
this._decorationOptionProviders.delete(key);
provider.dispose();
this.listCodeEditors().forEach((ed) => ed.removeDecorations(key));
}
@ -59,7 +58,7 @@ export abstract class CodeEditorServiceImpl extends AbstractCodeEditorService {
}
public resolveDecorationOptions(decorationTypeKey: string, writable: boolean): IModelDecorationOptions {
const provider = this._decorationOptionProviders[decorationTypeKey];
const provider = this._decorationOptionProviders.get(decorationTypeKey);
if (!provider) {
throw new Error('Unknown decoration type key: ' + decorationTypeKey);
}

View file

@ -36,7 +36,7 @@ export class ColorDetector extends Disposable implements IEditorContribution {
private _colorDatas = new Map<string, IColorData>();
private _colorDecoratorIds: string[] = [];
private readonly _decorationsTypes: { [key: string]: boolean } = {};
private readonly _decorationsTypes = new Set<string>();
private _isEnabled: boolean;
@ -180,7 +180,7 @@ export class ColorDetector extends Disposable implements IEditorContribution {
let color = `rgba(${rgba.r}, ${rgba.g}, ${rgba.b}, ${rgba.a})`;
let key = 'colorBox-' + subKey;
if (!this._decorationsTypes[key] && !newDecorationsTypes[key]) {
if (!this._decorationsTypes.has(key) && !newDecorationsTypes[key]) {
this._codeEditorService.registerDecorationType(key, {
before: {
contentText: ' ',
@ -210,7 +210,7 @@ export class ColorDetector extends Disposable implements IEditorContribution {
});
}
for (let subType in this._decorationsTypes) {
for (const subType of this._decorationsTypes) {
if (!newDecorationsTypes[subType]) {
this._codeEditorService.removeDecorationType(subType);
}
@ -223,7 +223,7 @@ export class ColorDetector extends Disposable implements IEditorContribution {
this._decorationsIds = this._editor.deltaDecorations(this._decorationsIds, []);
this._colorDecoratorIds = this._editor.deltaDecorations(this._colorDecoratorIds, []);
for (let subType in this._decorationsTypes) {
for (const subType of this._decorationsTypes) {
this._codeEditorService.removeDecorationType(subType);
}
}