]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed icons loading speed.
authorAlex Rousskov <rousskov@measurement-factory.com>
Fri, 20 May 2016 18:16:19 +0000 (12:16 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Fri, 20 May 2016 18:16:19 +0000 (12:16 -0600)
Since trunk r14100 (Bug 3875: bad mimeLoadIconFile error handling), each
icon was read from disk and written to Store one character at a time. I
did not measure startup delays in production, but in debugging runs,
fixing this bug sped up icons loading from 1 minute to 4 seconds.

src/mime.cc

index a2b638301df27325d7e87ba74c0f1443bd71e5aa..c96c7151283b3e2325eedae2c2f31cc79aa9cc53 100644 (file)
@@ -24,6 +24,8 @@
 #include "Store.h"
 #include "StoreClient.h"
 
+#include <array>
+
 #if HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
@@ -422,12 +424,11 @@ MimeIcon::created(StoreEntry *newEntry)
     if (status == Http::scOkay) {
         /* read the file into the buffer and append it to store */
         int n;
-        char *buf = (char *)memAllocate(MEM_4K_BUF);
-        while ((n = FD_READ_METHOD(fd, buf, sizeof(*buf))) > 0)
-            e->append(buf, n);
+        std::array<char, 4096> buf;
+        while ((n = FD_READ_METHOD(fd, buf.data(), buf.size())) > 0)
+            e->append(buf.data(), n);
 
         file_close(fd);
-        memFree(buf, MEM_4K_BUF);
     }
 
     e->flush();