Skip to content

Commit

Permalink
Move back to using walk on complete config as getValue for multiple k…
Browse files Browse the repository at this point in the history
…eys is slow
  • Loading branch information
sandy081 committed Nov 9, 2017
1 parent aa14fc5 commit 64f5272
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/vs/platform/contextkey/browser/contextKeyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,31 +93,46 @@ class ConfigAwareContextValuesContainer extends Context {
private _initFromConfiguration() {

const prefix = 'config.';
const config = this._configurationService.getConfiguration();
const configKeys: { [key: string]: boolean } = Object.create(null);

// add/update keys
const configProps = Registry.as<IConfigurationRegistry>(Extensions.Configuration).getConfigurationProperties();
for (const key in configProps) {
const node = configProps[key];
if (node.type === 'boolean') {
const value = this._configurationService.getValue(key);
const configKey = prefix + key;
const oldValue = this._value[configKey];
this._value[configKey] = value;
configKeys[configKey] = oldValue !== value;
const configKeysChanged: string[] = [];

// add new value from config
const walk = (obj: any, keys: string[]) => {
for (let key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
keys.push(key);
let value = obj[key];
if (typeof value === 'boolean') {
const configKey = keys.join('.');
const oldValue = this._value[configKey];
this._value[configKey] = value;
if (oldValue !== value) {
configKeysChanged.push(configKey);
configKeys[configKey] = true;
} else {
configKeys[configKey] = false;
}
} else if (typeof value === 'object') {
walk(value, keys);
}
keys.pop();
}
}
}
};
walk(config, ['config']);

// remove unused keys
for (let key in this._value) {
if (key.indexOf(prefix) === 0 && configKeys[key] === undefined) {
delete this._value[key];
configKeys[key] = true;
configKeysChanged.push(key);
}
}

// send events
this._emitter.fire(Object.keys(configKeys));
this._emitter.fire(configKeysChanged);
}
}

Expand Down

0 comments on commit 64f5272

Please sign in to comment.