From e366aa3746bd6dc37306fba1a78e17e79bf5d278 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Mon, 14 Apr 2014 09:02:52 +0100 Subject: [PATCH] Use Date.now() instead of new Date() Just for when what we actually want is a millisecond counter. Interesting video about this: https://www.youtube.com/watch?v=Vo72W1HWeFI --- core/modules/syncer.js | 6 +++--- core/modules/utils/dom/scroller.js | 4 ++-- core/modules/utils/utils.js | 2 +- core/modules/widgets/scrollable.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/modules/syncer.js b/core/modules/syncer.js index 838c9092c..60caf0983 100644 --- a/core/modules/syncer.js +++ b/core/modules/syncer.js @@ -267,7 +267,7 @@ Synchronise a set of changes to the server */ Syncer.prototype.syncToServer = function(changes) { var self = this, - now = new Date(), + now = Date.now(), filteredChanges = this.filterFn.call(this.wiki,function(callback) { $tw.utils.each(changes,function(change,title) { var tiddler = self.wiki.getTiddler(title); @@ -371,7 +371,7 @@ Queue up a sync task. If there is already a pending task for the tiddler, just u */ Syncer.prototype.enqueueSyncTask = function(task) { var self = this, - now = new Date(); + now = Date.now(); // Set the timestamps on this task task.queueTime = now; task.lastModificationTime = now; @@ -474,7 +474,7 @@ Choose the next applicable task Syncer.prototype.chooseNextTask = function() { var self = this, candidateTask = null, - now = new Date(); + now = Date.now(); // Select the best candidate task $tw.utils.each(this.taskQueue,function(task,title) { // Exclude the task if there's one of the same name in progress diff --git a/core/modules/utils/dom/scroller.js b/core/modules/utils/dom/scroller.js index 107a74449..8ff0e04c6 100644 --- a/core/modules/utils/dom/scroller.js +++ b/core/modules/utils/dom/scroller.js @@ -57,7 +57,7 @@ PageScroller.prototype.scrollIntoView = function(element) { var duration = $tw.utils.getAnimationDuration(); // Now get ready to scroll the body this.cancelScroll(); - this.startTime = new Date(); + this.startTime = Date.now(); var scrollPosition = $tw.utils.getScrollPosition(); // Get the client bounds of the element and adjust by the scroll position var clientBounds = element.getBoundingClientRect(), @@ -94,7 +94,7 @@ PageScroller.prototype.scrollIntoView = function(element) { if(duration <= 0) { t = 1; } else { - t = ((new Date()) - self.startTime) / duration; + t = ((Date.now()) - self.startTime) / duration; } if(t >= 1) { self.cancelScroll(); diff --git a/core/modules/utils/utils.js b/core/modules/utils/utils.js index 7848c4e94..cf92a95b7 100644 --- a/core/modules/utils/utils.js +++ b/core/modules/utils/utils.js @@ -475,7 +475,7 @@ exports.timer = function(base) { } else if(window.performance) { m = performance.now(); } else { - m = new Date(); + m = Date.now(); } if(typeof base !== "undefined") { m = m - base; diff --git a/core/modules/widgets/scrollable.js b/core/modules/widgets/scrollable.js index c5e244916..aa3d8c63e 100644 --- a/core/modules/widgets/scrollable.js +++ b/core/modules/widgets/scrollable.js @@ -68,7 +68,7 @@ Scroll an element into view ScrollableWidget.prototype.scrollIntoView = function(element) { var duration = $tw.utils.getAnimationDuration(); this.cancelScroll(); - this.startTime = new Date(); + this.startTime = Date.now(); var scrollPosition = { x: this.outerDomNode.scrollLeft, y: this.outerDomNode.scrollTop @@ -112,7 +112,7 @@ ScrollableWidget.prototype.scrollIntoView = function(element) { if(duration <= 0) { t = 1; } else { - t = ((new Date()) - self.startTime) / duration; + t = ((Date.now()) - self.startTime) / duration; } if(t >= 1) { self.cancelScroll();