From 810ff89ea71f5a78915ae7e2b5f5dda5de062d41 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Sat, 11 Apr 2020 16:29:56 +0300 Subject: [PATCH] FpsCounter: Use a const instead of generating a new time::Duration each tick Former-commit-id: e0b6ec4bbc97119f6e82d1219d1406626b50e890 --- rustboyadvance-core/src/util.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rustboyadvance-core/src/util.rs b/rustboyadvance-core/src/util.rs index aef7346..7ed805e 100644 --- a/rustboyadvance-core/src/util.rs +++ b/rustboyadvance-core/src/util.rs @@ -66,6 +66,8 @@ pub struct FpsCounter { timer: time::Instant, } +const SECOND: time::Duration = time::Duration::from_secs(1); + impl Default for FpsCounter { fn default() -> FpsCounter { FpsCounter { @@ -78,7 +80,7 @@ impl Default for FpsCounter { impl FpsCounter { pub fn tick(&mut self) -> Option { self.count += 1; - if self.timer.elapsed() >= time::Duration::from_secs(1) { + if self.timer.elapsed() >= SECOND { let fps = self.count; self.timer = time::Instant::now(); self.count = 0;