Optimize context object construction (#8413)

* perf: context construction
* avoid setPrototypeOf
This commit is contained in:
Jukka Kurkela
2021-02-14 17:34:49 +02:00
committed by GitHub
parent 6de5b3fa9e
commit 422d26d32a
3 changed files with 25 additions and 69 deletions

View File

@@ -737,14 +737,7 @@ class Chart {
}
getContext() {
return this.$context || (this.$context = Object.create(null, {
chart: {
value: this
},
type: {
value: 'chart'
}
}));
return this.$context || (this.$context = {chart: this, type: 'chart'});
}
getVisibleDatasetCount() {

View File

@@ -149,54 +149,27 @@ function getFirstScaleId(chart, axis) {
}
function createDatasetContext(parent, index, dataset) {
return Object.create(parent, {
active: {
writable: true,
value: false
},
dataset: {
value: dataset
},
datasetIndex: {
value: index
},
index: {
get() {
return this.datasetIndex;
}
},
type: {
value: 'dataset'
return Object.assign(Object.create(parent),
{
active: false,
dataset,
datasetIndex: index,
index,
type: 'dataset'
}
});
);
}
function createDataContext(parent, index, point, raw, element) {
return Object.create(parent, {
active: {
writable: true,
value: false
},
dataIndex: {
value: index
},
parsed: {
value: point
},
raw: {
value: raw
},
element: {
value: element
},
index: {
get() {
return this.dataIndex;
}
},
type: {
value: 'data',
}
return Object.assign(Object.create(parent), {
active: false,
dataIndex: index,
parsed: point,
raw,
element,
index,
mode: 'default',
type: 'data'
});
}

View File

@@ -282,27 +282,17 @@ function skip(ticks, newTicks, spacing, majorStart, majorEnd) {
}
function createScaleContext(parent, scale) {
return Object.create(parent, {
scale: {
value: scale
},
type: {
value: 'scale'
}
return Object.assign(Object.create(parent), {
scale,
type: 'scale'
});
}
function createTickContext(parent, index, tick) {
return Object.create(parent, {
tick: {
value: tick
},
index: {
value: index
},
type: {
value: 'tick'
}
return Object.assign(Object.create(parent), {
tick,
index,
type: 'tick'
});
}