LibGfx: Skip manual cropping for the degenerate case

This commit is contained in:
Idan Horowitz 2025-08-04 14:34:00 +03:00 committed by Jelle Raaijmakers
commit e81c33da42
Notes: github-actions[bot] 2025-08-04 21:40:27 +00:00

View file

@ -160,6 +160,10 @@ void Bitmap::apply_mask(Gfx::Bitmap const& mask, MaskKind mask_kind)
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::cropped(Gfx::IntRect crop, Gfx::Color outside_color) const
{
// OPTIMIZATION: Skip slow manual copying for NO-OP crops
if (crop == rect())
return clone();
auto new_bitmap = TRY(Gfx::Bitmap::create(format(), alpha_type(), { crop.width(), crop.height() }));
for (int y = 0; y < crop.height(); ++y) {