diff options
author | Aziz Berkay Yesilyurt <abyesilyurt@gmail.com> | 2021-07-11 21:54:18 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-14 13:37:18 +0200 |
commit | d1028f8aed5a812e34c4de7d6b6e003d3ea8199e (patch) | |
tree | d9bfe5987a8c2f6f731ea99ac339a0247e27f6b9 /Userland/Libraries | |
parent | b70f2b00a3e77ca15aee60ff5058594e29337492 (diff) | |
download | serenity-d1028f8aed5a812e34c4de7d6b6e003d3ea8199e.zip |
LibGfx: Use clear_with capacity instead of clear in PNGWriter
Same vector was cleared up and filled in continuously.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGfx/PNGWriter.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Userland/Libraries/LibGfx/PNGWriter.cpp b/Userland/Libraries/LibGfx/PNGWriter.cpp index 2812aa29f8..f1e04e13ca 100644 --- a/Userland/Libraries/LibGfx/PNGWriter.cpp +++ b/Userland/Libraries/LibGfx/PNGWriter.cpp @@ -31,6 +31,9 @@ public: void add_u8(u8); + template<typename T> + void add(T*, size_t); + void store_type(); void store_data_length(); u32 crc(); @@ -93,6 +96,12 @@ requires(IsUnsigned<T>) void PNGChunk::add(T data) } template<typename T> +void PNGChunk::add(T* data, size_t size) +{ + m_data.append(data, size); +} + +template<typename T> void PNGChunk::add_as_little_endian(T data) { auto data_out = AK::convert_between_host_and_little_endian(data); @@ -117,7 +126,7 @@ void NonCompressibleBlock::add_byte_to_block(u8 data, PNGChunk& chunk) update_adler(data); if (full()) { add_block_to_chunk(chunk, false); - m_non_compressible_data.clear(); + m_non_compressible_data.clear_with_capacity(); } } @@ -131,9 +140,7 @@ void NonCompressibleBlock::add_block_to_chunk(PNGChunk& png_chunk, bool last) png_chunk.add_as_little_endian(len); png_chunk.add_as_little_endian(nlen); - for (auto non_compressed_byte : m_non_compressible_data) { - png_chunk.add_u8(non_compressed_byte); - } + png_chunk.add(m_non_compressible_data.data(), m_non_compressible_data.size()); } void NonCompressibleBlock::finalize(PNGChunk& chunk) |