From a492e2018de1271659732ef7634ee2b9eb3ba719 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sun, 1 Jan 2023 22:50:49 -0700 Subject: [PATCH] Userland: Silence warnings from ElapsedTimer::elapsed() type change We changed elapsed() to return i64 instead of int as that's what AK::Time::to_milliseconds() returns, causing a bunch of implicit lossy conversions in callers. Clean those up with a mix of type changes and casts. --- Userland/DevTools/Profiler/main.cpp | 2 +- Userland/Libraries/LibSoftGPU/Device.cpp | 2 +- Userland/Libraries/LibWeb/HighResolutionTime/Performance.h | 2 +- Userland/Services/WindowServer/Animation.cpp | 2 +- Userland/Services/WindowServer/WindowManager.cpp | 4 ++-- Userland/Shell/Builtin.cpp | 2 +- Userland/Utilities/abench.cpp | 5 ++--- 7 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Userland/DevTools/Profiler/main.cpp b/Userland/DevTools/Profiler/main.cpp index 2026ce46ef9..431b09d7fa3 100644 --- a/Userland/DevTools/Profiler/main.cpp +++ b/Userland/DevTools/Profiler/main.cpp @@ -327,7 +327,7 @@ static bool prompt_to_stop_profiling(pid_t pid, DeprecatedString const& process_ Core::ElapsedTimer clock; clock.start(); auto update_timer = Core::Timer::construct(100, [&] { - timer_label.set_text(DeprecatedString::formatted("{:.1} seconds", clock.elapsed() / 1000.0f)); + timer_label.set_text(DeprecatedString::formatted("{:.1} seconds", static_cast(clock.elapsed()) / 1000.0f)); }); auto& stop_button = widget->add("Stop"); diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp index a06f67b1a9f..a506880b0c5 100644 --- a/Userland/Libraries/LibSoftGPU/Device.cpp +++ b/Userland/Libraries/LibSoftGPU/Device.cpp @@ -1570,7 +1570,7 @@ void Device::draw_statistics_overlay(Gfx::Bitmap& target) static int frame_counter; frame_counter++; - int milliseconds = 0; + i64 milliseconds = 0; if (timer.is_valid()) milliseconds = timer.elapsed(); else diff --git a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h index b2b8cd01f45..2853b3c056e 100644 --- a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h +++ b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h @@ -17,7 +17,7 @@ class Performance final : public DOM::EventTarget { public: virtual ~Performance() override; - double now() const { return m_timer.elapsed(); } + double now() const { return static_cast(m_timer.elapsed()); } double time_origin() const; JS::GCPtr timing(); diff --git a/Userland/Services/WindowServer/Animation.cpp b/Userland/Services/WindowServer/Animation.cpp index 8f90694bda1..7fc47bfd8ea 100644 --- a/Userland/Services/WindowServer/Animation.cpp +++ b/Userland/Services/WindowServer/Animation.cpp @@ -47,7 +47,7 @@ void Animation::was_removed(Badge) bool Animation::update(Badge, Gfx::Painter& painter, Screen& screen, Gfx::DisjointIntRectSet& flush_rects) { - int elapsed_ms = m_timer.elapsed(); + i64 const elapsed_ms = m_timer.elapsed(); float progress = min((float)elapsed_ms / (float)m_duration, 1.0f); if (on_update) diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index a5c3de16f52..b72a5f706e3 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -1086,8 +1086,8 @@ auto WindowManager::DoubleClickInfo::metadata_for_button(MouseButton button) -> bool WindowManager::is_considered_doubleclick(MouseEvent const& event, DoubleClickInfo::ClickMetadata const& metadata) const { - int elapsed_since_last_click = metadata.clock.elapsed(); - if (elapsed_since_last_click < m_double_click_speed) { + i64 elapsed_ms_since_last_click = metadata.clock.elapsed(); + if (elapsed_ms_since_last_click < m_double_click_speed) { auto diff = event.position() - metadata.last_position; auto distance_travelled_squared = diff.x() * diff.x() + diff.y() * diff.y(); if (distance_travelled_squared <= (m_max_distance_for_double_click * m_max_distance_for_double_click)) diff --git a/Userland/Shell/Builtin.cpp b/Userland/Shell/Builtin.cpp index e0315d8ee91..770da10c410 100644 --- a/Userland/Shell/Builtin.cpp +++ b/Userland/Shell/Builtin.cpp @@ -1007,7 +1007,7 @@ int Shell::builtin_time(int argc, char const** argv) block_on_job(job); exit_code = job.exit_code(); } - iteration_times.add(timer.elapsed()); + iteration_times.add(static_cast(timer.elapsed())); } if (number_of_iterations == 1) { diff --git a/Userland/Utilities/abench.cpp b/Userland/Utilities/abench.cpp index d57e0c4018b..7ad08b38c94 100644 --- a/Userland/Utilities/abench.cpp +++ b/Userland/Utilities/abench.cpp @@ -40,7 +40,7 @@ ErrorOr serenity_main(Main::Arguments args) auto loader = maybe_loader.release_value(); Core::ElapsedTimer sample_timer { true }; - u64 total_loader_time = 0; + i64 total_loader_time = 0; int remaining_samples = sample_count > 0 ? sample_count : NumericLimits::max(); unsigned total_loaded_samples = 0; @@ -48,8 +48,7 @@ ErrorOr serenity_main(Main::Arguments args) if (remaining_samples > 0) { sample_timer = sample_timer.start_new(); auto samples = loader->get_more_samples(min(MAX_CHUNK_SIZE, remaining_samples)); - auto elapsed = static_cast(sample_timer.elapsed()); - total_loader_time += static_cast(elapsed); + total_loader_time += sample_timer.elapsed(); if (!samples.is_error()) { remaining_samples -= samples.value().size(); total_loaded_samples += samples.value().size();