summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndrew Kaster <akaster@serenityos.org>2023-01-01 22:38:53 -0700
committerLinus Groh <mail@linusgroh.de>2023-01-07 14:51:04 +0100
commitddf348daeb6a572609b517d808637333f5563822 (patch)
treec0086a0b57726dbb6bc9029bf46479b20f4fad08 /Userland
parent4afa6e264c91764d27f8f0674b2835cd37ca90ab (diff)
downloadserenity-ddf348daeb6a572609b517d808637333f5563822.zip
Everywhere: Use ElapsedTimer::elapsed_time() for comparisons
Simplify a lot of uses of ElapsedTimer by converting the callers to elapsed_time from elapsed, as the AK::Time returned is better for unit conversions and comparisons against constants.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/Browser/DownloadWidget.cpp2
-rw-r--r--Userland/Applications/FileManager/FileOperationProgressWidget.cpp6
-rw-r--r--Userland/Demos/CatDog/CatDog.cpp4
-rw-r--r--Userland/DevTools/HackStudio/LanguageClient.cpp6
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.cpp4
-rw-r--r--Userland/Libraries/LibVT/TerminalWidget.cpp4
-rw-r--r--Userland/Services/SystemServer/Service.cpp6
7 files changed, 21 insertions, 11 deletions
diff --git a/Userland/Applications/Browser/DownloadWidget.cpp b/Userland/Applications/Browser/DownloadWidget.cpp
index 05c548721f..9dcdd80322 100644
--- a/Userland/Applications/Browser/DownloadWidget.cpp
+++ b/Userland/Applications/Browser/DownloadWidget.cpp
@@ -128,7 +128,7 @@ void DownloadWidget::did_progress(Optional<u32> total_size, u32 downloaded_size)
StringBuilder builder;
builder.append("Downloaded "sv);
builder.append(human_readable_size(downloaded_size));
- builder.appendff(" in {} sec", m_elapsed_timer.elapsed() / 1000);
+ builder.appendff(" in {} sec", m_elapsed_timer.elapsed_time().to_seconds());
m_progress_label->set_text(builder.to_deprecated_string());
}
diff --git a/Userland/Applications/FileManager/FileOperationProgressWidget.cpp b/Userland/Applications/FileManager/FileOperationProgressWidget.cpp
index 3f6d2ed207..ed4f1a764d 100644
--- a/Userland/Applications/FileManager/FileOperationProgressWidget.cpp
+++ b/Userland/Applications/FileManager/FileOperationProgressWidget.cpp
@@ -141,13 +141,13 @@ void FileOperationProgressWidget::did_error(StringView message)
DeprecatedString FileOperationProgressWidget::estimate_time(off_t bytes_done, off_t total_byte_count)
{
- int elapsed = m_elapsed_timer.elapsed() / 1000;
+ i64 const elapsed_seconds = m_elapsed_timer.elapsed_time().to_seconds();
- if (bytes_done == 0 || elapsed < 3)
+ if (bytes_done == 0 || elapsed_seconds < 3)
return "Estimating...";
off_t bytes_left = total_byte_count - bytes_done;
- int seconds_remaining = (bytes_left * elapsed) / bytes_done;
+ int seconds_remaining = (bytes_left * elapsed_seconds) / bytes_done;
if (seconds_remaining < 30)
return DeprecatedString::formatted("{} seconds", 5 + seconds_remaining - seconds_remaining % 5);
diff --git a/Userland/Demos/CatDog/CatDog.cpp b/Userland/Demos/CatDog/CatDog.cpp
index ec6a14a817..5c84970112 100644
--- a/Userland/Demos/CatDog/CatDog.cpp
+++ b/Userland/Demos/CatDog/CatDog.cpp
@@ -100,6 +100,8 @@ bool CatDog::is_inspector() const
void CatDog::timer_event(Core::TimerEvent&)
{
+ using namespace AK::TimeLiterals;
+
if (has_flag(m_state, State::Alert))
return;
@@ -127,7 +129,7 @@ void CatDog::timer_event(Core::TimerEvent&)
if (has_any_flag(m_state, State::Directions)) {
m_idle_sleep_timer.start();
} else {
- if (m_idle_sleep_timer.elapsed() > 5'000)
+ if (m_idle_sleep_timer.elapsed_time() > 5_sec)
m_state |= State::Sleeping;
else
m_state |= State::Idle;
diff --git a/Userland/DevTools/HackStudio/LanguageClient.cpp b/Userland/DevTools/HackStudio/LanguageClient.cpp
index c75db03823..11c02c46e3 100644
--- a/Userland/DevTools/HackStudio/LanguageClient.cpp
+++ b/Userland/DevTools/HackStudio/LanguageClient.cpp
@@ -192,11 +192,13 @@ ConnectionToServerWrapper* ConnectionToServerInstances::get_instance_wrapper(Dep
void ConnectionToServerWrapper::on_crash()
{
+ using namespace AK::TimeLiterals;
+
show_crash_notification();
m_connection.clear();
- static constexpr int max_crash_frequency_seconds = 10;
- if (m_last_crash_timer.is_valid() && m_last_crash_timer.elapsed() / 1000 < max_crash_frequency_seconds) {
+ static constexpr Time max_crash_frequency = 10_sec;
+ if (m_last_crash_timer.is_valid() && m_last_crash_timer.elapsed_time() < max_crash_frequency) {
dbgln("LanguageServer crash frequency is too high");
m_respawn_allowed = false;
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp
index 3e7361cd5b..b75d851b10 100644
--- a/Userland/Libraries/LibGUI/TextEditor.cpp
+++ b/Userland/Libraries/LibGUI/TextEditor.cpp
@@ -252,6 +252,8 @@ void TextEditor::doubleclick_event(MouseEvent& event)
void TextEditor::mousedown_event(MouseEvent& event)
{
+ using namespace AK::TimeLiterals;
+
if (event.button() != MouseButton::Primary) {
return;
}
@@ -262,7 +264,7 @@ void TextEditor::mousedown_event(MouseEvent& event)
if (is_displayonly())
return;
- if (m_triple_click_timer.is_valid() && m_triple_click_timer.elapsed() < 250) {
+ if (m_triple_click_timer.is_valid() && m_triple_click_timer.elapsed_time() < 250_ms) {
m_triple_click_timer = Core::ElapsedTimer();
select_current_line();
return;
diff --git a/Userland/Libraries/LibVT/TerminalWidget.cpp b/Userland/Libraries/LibVT/TerminalWidget.cpp
index 774f302276..7b5af7c115 100644
--- a/Userland/Libraries/LibVT/TerminalWidget.cpp
+++ b/Userland/Libraries/LibVT/TerminalWidget.cpp
@@ -795,6 +795,8 @@ void TerminalWidget::mouseup_event(GUI::MouseEvent& event)
void TerminalWidget::mousedown_event(GUI::MouseEvent& event)
{
+ using namespace AK::TimeLiterals;
+
if (event.button() == GUI::MouseButton::Primary) {
m_left_mousedown_position = event.position();
m_left_mousedown_position_buffer = buffer_position_at(m_left_mousedown_position);
@@ -809,7 +811,7 @@ void TerminalWidget::mousedown_event(GUI::MouseEvent& event)
m_active_href = {};
m_active_href_id = {};
- if (m_triple_click_timer.is_valid() && m_triple_click_timer.elapsed() < 250) {
+ if (m_triple_click_timer.is_valid() && m_triple_click_timer.elapsed_time() < 250_ms) {
int start_column = 0;
int end_column = m_terminal.columns() - 1;
diff --git a/Userland/Services/SystemServer/Service.cpp b/Userland/Services/SystemServer/Service.cpp
index 0d2d294d6d..147ba28047 100644
--- a/Userland/Services/SystemServer/Service.cpp
+++ b/Userland/Services/SystemServer/Service.cpp
@@ -243,6 +243,8 @@ void Service::spawn(int socket_fd)
void Service::did_exit(int exit_code)
{
+ using namespace AK::TimeLiterals;
+
VERIFY(m_pid > 0);
VERIFY(!m_multi_instance);
@@ -254,10 +256,10 @@ void Service::did_exit(int exit_code)
if (!m_keep_alive)
return;
- int run_time_in_msec = m_run_timer.elapsed();
+ auto run_time = m_run_timer.elapsed_time();
bool exited_successfully = exit_code == 0;
- if (!exited_successfully && run_time_in_msec < 1000) {
+ if (!exited_successfully && run_time < 1_sec) {
switch (m_restart_attempts) {
case 0:
dbgln("Trying again");