diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-09-12 08:21:16 -0700 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-09-12 17:24:44 +0000 |
commit | a2ee38768309814af44dc630f8b6f9fb5ff0b9b3 (patch) | |
tree | c2ebbedf4bb3520521ae85f9d5c071a553016e9e /Userland | |
parent | 500a3fb2a7a126fd2cf74eac3bc342e87549eb2c (diff) | |
download | serenity-a2ee38768309814af44dc630f8b6f9fb5ff0b9b3.zip |
LibCore: Add factory to create and start a new ElapsedTimer
Simplifies one of the main usage patterns of the timer class.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibCore/ElapsedTimer.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibCore/ElapsedTimer.h | 2 |
2 files changed, 9 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/ElapsedTimer.cpp b/Userland/Libraries/LibCore/ElapsedTimer.cpp index 96490310cf..59b4b4cd95 100644 --- a/Userland/Libraries/LibCore/ElapsedTimer.cpp +++ b/Userland/Libraries/LibCore/ElapsedTimer.cpp @@ -12,6 +12,13 @@ namespace Core { +ElapsedTimer ElapsedTimer::start_new() +{ + ElapsedTimer timer; + timer.start(); + return timer; +} + void ElapsedTimer::start() { m_valid = true; diff --git a/Userland/Libraries/LibCore/ElapsedTimer.h b/Userland/Libraries/LibCore/ElapsedTimer.h index d675802178..f230f34068 100644 --- a/Userland/Libraries/LibCore/ElapsedTimer.h +++ b/Userland/Libraries/LibCore/ElapsedTimer.h @@ -13,6 +13,8 @@ namespace Core { class ElapsedTimer { public: + static ElapsedTimer start_new(); + ElapsedTimer(bool precise = false) : m_precise(precise) { |