From c7f7c1f7f0914132f77f3e8bf38ba9e416fa97aa Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 12 Jun 2021 09:45:07 +0200 Subject: [PATCH] PixelPaint: Use move semantics around Layer construction and accessors --- Userland/Applications/PixelPaint/Image.cpp | 4 +++- Userland/Applications/PixelPaint/Layer.cpp | 20 ++++++++++---------- Userland/Applications/PixelPaint/Layer.h | 12 ++++++------ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp index a756470cc31..967443c737b 100644 --- a/Userland/Applications/PixelPaint/Image.cpp +++ b/Userland/Applications/PixelPaint/Image.cpp @@ -98,7 +98,9 @@ RefPtr Image::try_create_from_pixel_paint_file(String const& file_path) auto bitmap_base64_encoded = json_layer_object.get("bitmap").as_string(); auto bitmap_data = decode_base64(bitmap_base64_encoded); auto image_decoder = Gfx::ImageDecoder::create(bitmap_data); - layer->set_bitmap(*image_decoder->bitmap()); + auto bitmap = image_decoder->bitmap(); + VERIFY(bitmap); + layer->set_bitmap(bitmap.release_nonnull()); image->add_layer(*layer); }); diff --git a/Userland/Applications/PixelPaint/Layer.cpp b/Userland/Applications/PixelPaint/Layer.cpp index 2b483f78850..5c1125c3bb8 100644 --- a/Userland/Applications/PixelPaint/Layer.cpp +++ b/Userland/Applications/PixelPaint/Layer.cpp @@ -10,7 +10,7 @@ namespace PixelPaint { -RefPtr Layer::try_create_with_size(Image& image, Gfx::IntSize const& size, String const& name) +RefPtr Layer::try_create_with_size(Image& image, Gfx::IntSize const& size, String name) { if (size.is_empty()) return nullptr; @@ -18,10 +18,10 @@ RefPtr Layer::try_create_with_size(Image& image, Gfx::IntSize const& size if (size.width() > 16384 || size.height() > 16384) return nullptr; - return adopt_ref(*new Layer(image, size, name)); + return adopt_ref(*new Layer(image, size, move(name))); } -RefPtr Layer::try_create_with_bitmap(Image& image, Gfx::Bitmap const& bitmap, String const& name) +RefPtr Layer::try_create_with_bitmap(Image& image, Gfx::Bitmap const& bitmap, String name) { if (bitmap.size().is_empty()) return nullptr; @@ -29,7 +29,7 @@ RefPtr Layer::try_create_with_bitmap(Image& image, Gfx::Bitmap const& bit if (bitmap.size().width() > 16384 || bitmap.size().height() > 16384) return nullptr; - return adopt_ref(*new Layer(image, bitmap, name)); + return adopt_ref(*new Layer(image, bitmap, move(name))); } RefPtr Layer::try_create_snapshot(Image& image, Layer const& layer) @@ -49,16 +49,16 @@ RefPtr Layer::try_create_snapshot(Image& image, Layer const& layer) return snapshot; } -Layer::Layer(Image& image, Gfx::IntSize const& size, String const& name) +Layer::Layer(Image& image, Gfx::IntSize const& size, String name) : m_image(image) - , m_name(name) + , m_name(move(name)) { m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, size); } -Layer::Layer(Image& image, Gfx::Bitmap const& bitmap, String const& name) +Layer::Layer(Image& image, Gfx::Bitmap const& bitmap, String name) : m_image(image) - , m_name(name) + , m_name(move(name)) , m_bitmap(bitmap) { } @@ -84,11 +84,11 @@ void Layer::set_opacity_percent(int opacity_percent) m_image.layer_did_modify_properties({}, *this); } -void Layer::set_name(String const& name) +void Layer::set_name(String name) { if (m_name == name) return; - m_name = name; + m_name = move(name); m_image.layer_did_modify_properties({}, *this); } diff --git a/Userland/Applications/PixelPaint/Layer.h b/Userland/Applications/PixelPaint/Layer.h index 8286ed84a0c..846aab6ee5a 100644 --- a/Userland/Applications/PixelPaint/Layer.h +++ b/Userland/Applications/PixelPaint/Layer.h @@ -24,8 +24,8 @@ class Layer AK_MAKE_NONMOVABLE(Layer); public: - static RefPtr try_create_with_size(Image&, Gfx::IntSize const&, String const& name); - static RefPtr try_create_with_bitmap(Image&, Gfx::Bitmap const&, String const& name); + static RefPtr try_create_with_size(Image&, Gfx::IntSize const&, String name); + static RefPtr try_create_with_bitmap(Image&, Gfx::Bitmap const&, String name); static RefPtr try_create_snapshot(Image&, Layer const&); ~Layer() { } @@ -41,9 +41,9 @@ public: Gfx::IntRect rect() const { return { {}, size() }; } String const& name() const { return m_name; } - void set_name(String const&); + void set_name(String); - void set_bitmap(Gfx::Bitmap& bitmap) { m_bitmap = bitmap; } + void set_bitmap(NonnullRefPtr bitmap) { m_bitmap = move(bitmap); } void did_modify_bitmap(Image&); @@ -57,8 +57,8 @@ public: void set_opacity_percent(int); private: - Layer(Image&, Gfx::IntSize const&, String const& name); - Layer(Image&, Gfx::Bitmap const&, String const& name); + Layer(Image&, Gfx::IntSize const&, String name); + Layer(Image&, Gfx::Bitmap const&, String name); Image& m_image;