From: Jukka Kurkela Date: Sun, 14 Feb 2021 15:34:49 +0000 (+0200) Subject: Optimize context object construction (#8413) X-Git-Tag: v3.0.0-beta.11~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=422d26d32ab9efb2fcc3a17a94a1464bc65ab710;p=thirdparty%2FChart.js.git Optimize context object construction (#8413) * perf: context construction * avoid setPrototypeOf --- diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 04ec4c191..fce289cf0 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -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() { diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index b5f50fd09..a06946b1f 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -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' }); } diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 70fdfaca6..00eff1fd2 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -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' }); }