]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
cache also undefined values in option resolver (#9661)
authorToni Dietze <Flupp@users.noreply.github.com>
Mon, 4 Oct 2021 18:02:45 +0000 (20:02 +0200)
committerGitHub <noreply@github.com>
Mon, 4 Oct 2021 18:02:45 +0000 (14:02 -0400)
Otherwise, repeated lookups of undefined properties always trigger the
comparatively expensive resolution. This can be the case for example in
_calculateBarIndexPixels() in controller.bar.js when looking up
options.skipNull and options.maxBarThickness, which is done for each bar
in a bar chart.

src/helpers/helpers.config.js

index ce78ec68fa917548d0beeb617837bde57661ad85..f59ed31f6eb16a74fb21c2ccdacbea953d8f46e1 100644 (file)
@@ -181,17 +181,13 @@ const readKey = (prefix, name) => prefix ? prefix + _capitalize(name) : name;
 const needsSubResolver = (prop, value) => isObject(value) && prop !== 'adapters';
 
 function _cached(target, prop, resolve) {
-  let value = target[prop]; // cached value
-  if (defined(value)) {
-    return value;
+  if (Object.prototype.hasOwnProperty.call(target, prop)) {
+    return target[prop];
   }
 
-  value = resolve();
-
-  if (defined(value)) {
-    // cache the resolved value
-    target[prop] = value;
-  }
+  const value = resolve();
+  // cache the resolved value
+  target[prop] = value;
   return value;
 }