mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 15:32:40 -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,12 +27,11 @@ Timer.prototype.startTime = 0;
|
||||||
* Return the currently known absolute time, in ms precision.
|
* Return the currently known absolute time, in ms precision.
|
||||||
* @returns {number} ms elapsed since 1 January 1970 00:00:00 UTC.
|
* @returns {number} ms elapsed since 1 January 1970 00:00:00 UTC.
|
||||||
*/
|
*/
|
||||||
Timer.prototype.time = function () {
|
Timer.prototype.time = Date.now ?
|
||||||
if (Date.now) {
|
function () {
|
||||||
return Date.now();
|
return Date.now();
|
||||||
} else {
|
} : function () {
|
||||||
return new Date().getTime();
|
return new Date().getTime();
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,13 +41,12 @@ Timer.prototype.time = function () {
|
||||||
* Not guaranteed to produce the same absolute values per-system.
|
* Not guaranteed to produce the same absolute values per-system.
|
||||||
* @returns {number} ms-scale accurate time relative to other relative times.
|
* @returns {number} ms-scale accurate time relative to other relative times.
|
||||||
*/
|
*/
|
||||||
Timer.prototype.relativeTime = function () {
|
Timer.prototype.relativeTime =
|
||||||
if (typeof self !== 'undefined' &&
|
(typeof self !== 'undefined' && self.performance && 'now' in self.performance) ?
|
||||||
self.performance && 'now' in self.performance) {
|
function () {
|
||||||
return self.performance.now();
|
return self.performance.now();
|
||||||
} else {
|
} : function () {
|
||||||
return this.time();
|
return this.time();
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue