浏览代码

PNGLoader: Allocate enough space for the compressed data buffer up front.

This is a 2x speedup on wallpaper loading.
Andreas Kling 6 年之前
父节点
当前提交
fe25f957e5
共有 1 个文件被更改,包括 4 次插入3 次删除
  1. 4 3
      SharedGraphics/PNGLoader.cpp

+ 4 - 3
SharedGraphics/PNGLoader.cpp

@@ -99,7 +99,6 @@ static bool process_chunk(Streamer&, PNGLoadingContext& context);
 
 RetainPtr<GraphicsBitmap> load_png(const String& path)
 {
-    Stopwatch sw("load_png");
     int fd = open(path.characters(), O_RDONLY);
     if (fd < 0) {
         perror("open");
@@ -153,7 +152,7 @@ static byte paeth_predictor(int a, int b, int c)
 
 static RetainPtr<GraphicsBitmap> load_png_impl(const byte* data, int data_size)
 {
-    Stopwatch sw("load_png_impl");
+    Stopwatch sw("load_png_impl: total");
     const byte* data_ptr = data;
     int data_remaining = data_size;
 
@@ -165,6 +164,8 @@ static RetainPtr<GraphicsBitmap> load_png_impl(const byte* data, int data_size)
 
     PNGLoadingContext context;
 
+    context.compressed_data.ensure_capacity(data_size);
+
     data_ptr += sizeof(png_header);
     data_remaining -= sizeof(png_header);
 
@@ -205,7 +206,7 @@ static RetainPtr<GraphicsBitmap> load_png_impl(const byte* data, int data_size)
     }
 
     {
-        Stopwatch sw("create bitmap");
+        Stopwatch sw("load_png_impl: create bitmap");
         context.bitmap = GraphicsBitmap::create(GraphicsBitmap::Format::RGBA32, { context.width, context.height });
     }