From bd405ecc4aabce1b157331bdc00d2b3525988d9b Mon Sep 17 00:00:00 2001 From: griffpatch Date: Sat, 28 Jan 2017 16:43:37 +0000 Subject: [PATCH] Optimisation - Only check browser compatability once This saves doing the checks everytime the time functions are referenced --- src/util/timer.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/util/timer.js b/src/util/timer.js index 17c66a567..a0b620112 100644 --- a/src/util/timer.js +++ b/src/util/timer.js @@ -27,13 +27,12 @@ Timer.prototype.startTime = 0; * Return the currently known absolute time, in ms precision. * @returns {number} ms elapsed since 1 January 1970 00:00:00 UTC. */ -Timer.prototype.time = function () { - if (Date.now) { +Timer.prototype.time = Date.now ? + function () { return Date.now(); - } else { + } : function () { return new Date().getTime(); - } -}; + }; /** * Returns a time accurate relative to other times produced by this function. @@ -42,14 +41,13 @@ Timer.prototype.time = function () { * Not guaranteed to produce the same absolute values per-system. * @returns {number} ms-scale accurate time relative to other relative times. */ -Timer.prototype.relativeTime = function () { - if (typeof self !== 'undefined' && - self.performance && 'now' in self.performance) { - return self.performance.now(); - } else { - return this.time(); - } -}; +Timer.prototype.relativeTime = + (typeof self !== 'undefined' && self.performance && 'now' in self.performance) ? + function () { + return self.performance.now(); + } : function () { + return this.time(); + }; /** * Start a timer for measuring elapsed time,