]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Optimize context object construction (#8413)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Sun, 14 Feb 2021 15:34:49 +0000 (17:34 +0200)
committerGitHub <noreply@github.com>
Sun, 14 Feb 2021 15:34:49 +0000 (10:34 -0500)
* perf: context construction
* avoid setPrototypeOf

src/core/core.controller.js
src/core/core.datasetController.js
src/core/core.scale.js

index 04ec4c191c5cefaee3f6a72abd0a946186fceb62..fce289cf0c534e2569e272a55a5a63b31fb6983d 100644 (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() {
index b5f50fd091ce3ef8ad2d10719abab43ae7d30f51..a06946b1f029a5ad99f8ae74b8d61172aed8ca96 100644 (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'
   });
 }
 
index 70fdfaca695c2ed212995d86a9621092117090d3..00eff1fd292545fd7881026bd44b58797d487e48 100644 (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'
   });
 }