diff options
author | Aziz Berkay Yesilyurt <abyesilyurt@gmail.com> | 2021-07-11 19:00:32 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-14 13:37:18 +0200 |
commit | db36ddc7630ef57d9e546610d4de6f95330c4d92 (patch) | |
tree | aafcd5f1039ae87827192b84a57dece09398f33e /Userland/Libraries | |
parent | d84c4b94da23d7d1b477e1cdc2e9c7ad4c2dd5a4 (diff) | |
download | serenity-db36ddc7630ef57d9e546610d4de6f95330c4d92.zip |
LibGfx: Prevent a copy in PNGWriter by storing type data at start
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGfx/PNGWriter.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/Userland/Libraries/LibGfx/PNGWriter.cpp b/Userland/Libraries/LibGfx/PNGWriter.cpp index 6e5978a24b..e9aa6cf693 100644 --- a/Userland/Libraries/LibGfx/PNGWriter.cpp +++ b/Userland/Libraries/LibGfx/PNGWriter.cpp @@ -28,6 +28,8 @@ public: void add_u8(u8); + void store_type(); + private: template<typename T> requires(IsUnsigned<T>) void add(T); @@ -56,6 +58,14 @@ private: PNGChunk::PNGChunk(String type) : m_type(move(type)) { + store_type(); +} + +void PNGChunk::store_type() +{ + for (auto character : type()) { + m_data.append(&character, sizeof(character)); + } } template<typename T> @@ -121,19 +131,12 @@ void NonCompressibleBlock::update_adler(u8 data) void PNGWriter::add_chunk(PNGChunk const& png_chunk) { - ByteBuffer combined; - for (auto character : png_chunk.type()) { - combined.append(&character, sizeof(character)); - } - - combined.append(png_chunk.data().data(), png_chunk.data().size()); - - auto crc = BigEndian(Crypto::Checksum::CRC32({ (const u8*)combined.data(), combined.size() }).digest()); - auto data_len = BigEndian(png_chunk.data().size()); + auto crc = BigEndian(Crypto::Checksum::CRC32({ (const u8*)png_chunk.data().data(), png_chunk.data().size() }).digest()); + auto data_len = BigEndian(png_chunk.data().size() - png_chunk.type().length()); ByteBuffer buf; buf.append(&data_len, sizeof(u32)); - buf.append(combined.data(), combined.size()); + buf.append(png_chunk.data().data(), png_chunk.data().size()); buf.append(&crc, sizeof(u32)); m_data.append(buf.data(), buf.size()); |