diff options
author | Richard Wilson <rjw@netsurf-browser.org> | 2005-04-05 02:36:33 +0000 |
---|---|---|
committer | Richard Wilson <rjw@netsurf-browser.org> | 2005-04-05 02:36:33 +0000 |
commit | 92743be24d5ccc99de21dee81ee36307b94877a7 (patch) | |
tree | 45dbd7bd702b920ef6f197d730995e6ebff598dc /content/content.c | |
parent | 57c30e59f270afc02d4bdbc0b0fbcd509302c195 (diff) | |
download | netsurf-92743be24d5ccc99de21dee81ee36307b94877a7.tar.gz netsurf-92743be24d5ccc99de21dee81ee36307b94877a7.tar.bz2 |
[project @ 2005-04-05 02:36:33 by rjw]
Reduce re-allocation of memory when receiving files (drastically increases the speed of loading large files locally). Sprite files no longer require two copies of their data.
svn path=/import/netsurf/; revision=1598
Diffstat (limited to 'content/content.c')
-rw-r--r-- | content/content.c | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/content/content.c b/content/content.c index 9e113cac0..b80d5de89 100644 --- a/content/content.c +++ b/content/content.c @@ -195,7 +195,7 @@ static const struct handler_entry handler_map[] = { 0, nsmng_destroy, 0, nsmng_redraw, 0, 0, false}, #endif #ifdef WITH_SPRITE - {sprite_create, sprite_process_data, sprite_convert, + {sprite_create, 0, sprite_convert, 0, sprite_destroy, 0, sprite_redraw, 0, 0, false}, #endif #ifdef WITH_DRAW @@ -290,6 +290,7 @@ struct content * content_create(const char *url) c->fetch = 0; c->source_data = 0; c->source_size = 0; + c->source_allocated = 0; c->total_size = 0; c->no_error_pages = false; c->download = false; @@ -475,29 +476,36 @@ bool content_process_data(struct content *c, const char *data, { char *source_data; union content_msg_data msg_data; + unsigned int extra_space; assert(c); assert(c->type < HANDLER_MAP_COUNT); assert(c->status == CONTENT_STATUS_LOADING); LOG(("content %s, size %u", c->url, size)); - source_data = talloc_realloc(c, c->source_data, char, - c->source_size + size); - if (!source_data) { - c->status = CONTENT_STATUS_ERROR; - msg_data.error = messages_get("NoMemory"); - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); - return false; + if ((c->source_size + size) > c->source_allocated) { + extra_space = (c->source_size + size) / 4; + if (extra_space < 65536) + extra_space = 65536; + source_data = talloc_realloc(c, c->source_data, char, + c->source_size + size + extra_space); + if (!source_data) { + c->status = CONTENT_STATUS_ERROR; + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + warn_user("NoMemory", 0); + return false; + } + c->source_data = source_data; + c->source_allocated = c->source_size + size + extra_space; } - c->source_data = source_data; memcpy(c->source_data + c->source_size, data, size); c->source_size += size; c->size += size; if (handler_map[c->type].process_data) { if (!handler_map[c->type].process_data(c, - source_data + c->source_size - size, size)) { + c->source_data + c->source_size - size, size)) { c->status = CONTENT_STATUS_ERROR; return false; } @@ -523,12 +531,22 @@ bool content_process_data(struct content *c, const char *data, void content_convert(struct content *c, int width, int height) { union content_msg_data msg_data; + char *source_data; assert(c); assert(c->type < HANDLER_MAP_COUNT); assert(c->status == CONTENT_STATUS_LOADING); LOG(("content %s", c->url)); + if (c->source_allocated != c->source_size) { + source_data = talloc_realloc(c, c->source_data, char, + c->source_size); + if (source_data) { + c->source_data = source_data; + c->source_allocated = c->source_size; + } + } + c->available_width = width; if (handler_map[c->type].convert) { if (!handler_map[c->type].convert(c, width, height)) { |