diff options
author | Aziz Berkay Yesilyurt <abyesilyurt@gmail.com> | 2021-07-11 18:50:45 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-14 13:37:18 +0200 |
commit | d84c4b94da23d7d1b477e1cdc2e9c7ad4c2dd5a4 (patch) | |
tree | 1d7ceb5ca50ecd6a7e3a1b315905d32d3fbb4503 /Userland/Libraries | |
parent | 97859aaff1f22c5c718d6e271129a1f412ede83c (diff) | |
download | serenity-d84c4b94da23d7d1b477e1cdc2e9c7ad4c2dd5a4.zip |
LibGfx: Prevent frequent memory allocations in PNGWriter
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGfx/PNGWriter.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/PNGWriter.cpp b/Userland/Libraries/LibGfx/PNGWriter.cpp index 8efd4ced3f..6e5978a24b 100644 --- a/Userland/Libraries/LibGfx/PNGWriter.cpp +++ b/Userland/Libraries/LibGfx/PNGWriter.cpp @@ -18,6 +18,7 @@ public: explicit PNGChunk(String); auto const& data() const { return m_data; }; String const& type() const { return m_type; }; + void reserve(size_t bytes) { m_data.ensure_capacity(bytes); } template<typename T> void add_as_big_endian(T); @@ -166,6 +167,7 @@ void PNGWriter::add_IEND_chunk() void PNGWriter::add_IDAT_chunk(Gfx::Bitmap const& bitmap) { PNGChunk png_chunk { "IDAT" }; + png_chunk.reserve(bitmap.size_in_bytes()); u16 CMF_FLG = 0x81d; png_chunk.add_as_big_endian(CMF_FLG); |