Author: jmb
Date: Thu Sep 17 11:16:39 2009
New Revision: 9591
URL:
http://source.netsurf-browser.org?rev=9591&view=rev
Log:
Change image data reallocation strategy. Seriously improves performance with huge image
data.
Modified:
trunk/libnspng/src/pngread.c
Modified: trunk/libnspng/src/pngread.c
URL:
http://source.netsurf-browser.org/trunk/libnspng/src/pngread.c?rev=9591&a...
==============================================================================
--- trunk/libnspng/src/pngread.c (original)
+++ trunk/libnspng/src/pngread.c Thu Sep 17 11:16:39 2009
@@ -541,24 +541,25 @@
}
}
- if (max_idx + 1 > bps) {
+ if (max_idx + 1 > bps) {
+ const uint32_t required_size = image->data_len + bps;
uint8_t *temp;
uint32_t written;
/* Create/extend image buffer */
-#define OUTPUT_CHUNK_SIZE (16*1024)
- while (image->data_len + bps > image->data_alloc) {
- temp = ctx->alloc(image->data,
- image->data_alloc + OUTPUT_CHUNK_SIZE,
- ctx->pw);
+ if (required_size > image->data_alloc) {
+ /* Allocate an extra 12.5% to avoid heap thrashing */
+ const uint32_t new_size = required_size +
+ (required_size / 8);
+
+ temp = ctx->alloc(image->data, new_size, ctx->pw);
if (temp == NULL) {
return NSPNG_NOMEM;
}
image->data = temp;
- image->data_alloc += OUTPUT_CHUNK_SIZE;
- }
-#undef OUTPUT_CHUNK_SIZE
+ image->data_alloc = new_size;
+ }
/* Compress scanline into buffer */
written = lzf_compress(src_scanline,