From ceb43b5c4b7e9cc3e3d9983dccd3fd98bb43b875 Mon Sep 17 00:00:00 2001 From: Eric Mika Date: Mon, 18 Dec 2023 02:44:27 -0500 Subject: [PATCH] Avoid Date object creation. --- src/cubic-bezier/view/cubic-bezier-preview.ts | 4 ++-- src/fps-graph/controller/fps-graph.ts | 4 ++-- src/fps-graph/model/stopwatch.ts | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cubic-bezier/view/cubic-bezier-preview.ts b/src/cubic-bezier/view/cubic-bezier-preview.ts index a15fb09..8514dea 100644 --- a/src/cubic-bezier/view/cubic-bezier-preview.ts +++ b/src/cubic-bezier/view/cubic-bezier-preview.ts @@ -69,7 +69,7 @@ export class CubicBezierPreviewView implements View { this.updateMarker_(0); this.markerElem_.classList.add(className('m', 'a')); - this.startTime_ = new Date().getTime() + PREVIEW_DELAY; + this.startTime_ = Date.now() + PREVIEW_DELAY; this.stopped_ = false; requestAnimationFrame(this.onTimer_); } @@ -105,7 +105,7 @@ export class CubicBezierPreviewView implements View { return; } - const dt = new Date().getTime() - this.startTime_; + const dt = Date.now() - this.startTime_; const p = dt / PREVIEW_DURATION; this.updateMarker_(p); diff --git a/src/fps-graph/controller/fps-graph.ts b/src/fps-graph/controller/fps-graph.ts index cd19c3d..8a690e8 100644 --- a/src/fps-graph/controller/fps-graph.ts +++ b/src/fps-graph/controller/fps-graph.ts @@ -64,11 +64,11 @@ export class FpsGraphController implements Controller { } public begin(): void { - this.stopwatch_.begin(new Date()); + this.stopwatch_.begin(Date.now()); } public end(): void { - this.stopwatch_.end(new Date()); + this.stopwatch_.end(Date.now()); } private onTick_(): void { diff --git a/src/fps-graph/model/stopwatch.ts b/src/fps-graph/model/stopwatch.ts index a4fe0d1..b76d916 100644 --- a/src/fps-graph/model/stopwatch.ts +++ b/src/fps-graph/model/stopwatch.ts @@ -20,8 +20,8 @@ export class Fpswatch { return this.fps_; } - public begin(now: Date): void { - this.start_ = now.getTime(); + public begin(now: number): void { + this.start_ = now; } private calculateFps_(nowTime: number): number | null { @@ -48,12 +48,12 @@ export class Fpswatch { this.frameCount_ -= df; } - public end(now: Date): void { + public end(now: number): void { if (this.start_ === null) { return; } - const t = now.getTime(); + const t = now; this.duration_ = t - this.start_; this.start_ = null;