From c69b266e43ca85ed33ae3958823b7c35d7b7ef26 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 2 Mar 2024 10:48:15 +0100 Subject: [PATCH] LibGfx: Add fast path for multiply() with identity transforms This is a no-op, and exiting early is useful as it cuts time spent in AffineTransform::multiply() from 3% to 2% when hovering links on ziglang.org. --- Userland/Libraries/LibGfx/AffineTransform.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Userland/Libraries/LibGfx/AffineTransform.cpp b/Userland/Libraries/LibGfx/AffineTransform.cpp index b32258977e..97787b0f5d 100644 --- a/Userland/Libraries/LibGfx/AffineTransform.cpp +++ b/Userland/Libraries/LibGfx/AffineTransform.cpp @@ -108,6 +108,8 @@ AffineTransform& AffineTransform::set_translation(FloatPoint t) AffineTransform& AffineTransform::multiply(AffineTransform const& other) { + if (other.is_identity()) + return *this; AffineTransform result; result.m_values[0] = other.a() * a() + other.b() * c(); result.m_values[1] = other.a() * b() + other.b() * d();