From bc248d28f73dd298463b73a202258f3d7f95b19e Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 15 Mar 2023 11:30:19 +0100 Subject: LibGfx: Make PNGChunk::m_type a String instead of a DeprecatedString It's always 4 bytes, so the data fits in a String's inline buffer. (Else I would've used a StringView.) --- Userland/Libraries/LibGfx/PNGWriter.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'Userland/Libraries/LibGfx') diff --git a/Userland/Libraries/LibGfx/PNGWriter.cpp b/Userland/Libraries/LibGfx/PNGWriter.cpp index e6f772a2c1..f07baccef0 100644 --- a/Userland/Libraries/LibGfx/PNGWriter.cpp +++ b/Userland/Libraries/LibGfx/PNGWriter.cpp @@ -7,9 +7,9 @@ */ #include -#include #include #include +#include #include #include #include @@ -23,9 +23,9 @@ class PNGChunk { using data_length_type = u32; public: - explicit PNGChunk(DeprecatedString); + explicit PNGChunk(String); auto const& data() const { return m_data; }; - DeprecatedString const& type() const { return m_type; }; + String const& type() const { return m_type; }; ErrorOr reserve(size_t bytes) { return m_data.try_ensure_capacity(bytes); } template @@ -42,10 +42,10 @@ public: private: ByteBuffer m_data; - DeprecatedString m_type; + String m_type; }; -PNGChunk::PNGChunk(DeprecatedString type) +PNGChunk::PNGChunk(String type) : m_type(move(type)) { // NOTE: These are MUST() because they should always be able to fit in m_data's inline capacity. @@ -61,7 +61,7 @@ ErrorOr PNGChunk::store_type() void PNGChunk::store_data_length() { - auto data_length = BigEndian(m_data.size() - sizeof(data_length_type) - m_type.length()); + auto data_length = BigEndian(m_data.size() - sizeof(data_length_type) - m_type.bytes().size()); __builtin_memcpy(m_data.offset_pointer(0), &data_length, sizeof(u32)); } @@ -113,7 +113,7 @@ ErrorOr PNGWriter::add_png_header() ErrorOr PNGWriter::add_IHDR_chunk(u32 width, u32 height, u8 bit_depth, PNG::ColorType color_type, u8 compression_method, u8 filter_method, u8 interlace_method) { - PNGChunk png_chunk { "IHDR" }; + PNGChunk png_chunk { "IHDR"_short_string }; TRY(png_chunk.add_as_big_endian(width)); TRY(png_chunk.add_as_big_endian(height)); TRY(png_chunk.add_u8(bit_depth)); @@ -128,7 +128,7 @@ ErrorOr PNGWriter::add_IHDR_chunk(u32 width, u32 height, u8 bit_depth, PNG ErrorOr PNGWriter::add_iCCP_chunk(ReadonlyBytes icc_data) { // https://www.w3.org/TR/png/#11iCCP - PNGChunk chunk { "iCCP" }; + PNGChunk chunk { "iCCP"_short_string }; TRY(chunk.add("embedded profile"sv.bytes())); TRY(chunk.add_u8(0)); // \0-terminate profile name @@ -142,7 +142,7 @@ ErrorOr PNGWriter::add_iCCP_chunk(ReadonlyBytes icc_data) ErrorOr PNGWriter::add_IEND_chunk() { - PNGChunk png_chunk { "IEND" }; + PNGChunk png_chunk { "IEND"_short_string }; TRY(add_chunk(png_chunk)); return {}; } @@ -167,7 +167,7 @@ static_assert(AssertSize()); ErrorOr PNGWriter::add_IDAT_chunk(Gfx::Bitmap const& bitmap) { - PNGChunk png_chunk { "IDAT" }; + PNGChunk png_chunk { "IDAT"_short_string }; TRY(png_chunk.reserve(bitmap.size_in_bytes())); ByteBuffer uncompressed_block_data; -- cgit v1.2.3