mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 07:22:33 -05:00
Optimisation - Only check browser compatability once
This saves doing the checks everytime the time functions are referenced
This commit is contained in:
parent
824628220c
commit
bd405ecc4a
1 changed files with 11 additions and 13 deletions
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue