From d2e3f4e6b56d5826ec0ab976f1351b33b57f8f9f Mon Sep 17 00:00:00 2001 From: James Zern Date: Sat, 16 Nov 2013 10:57:09 -0800 Subject: [PATCH] demux: add a tail pointer for chunks a large number of non-frame chunks could slow the parse Change-Id: I181bc73626e92263c3c5b2a6dc2bf6e6a0481d52 --- src/demux/demux.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/demux/demux.c b/src/demux/demux.c index 08a7c8ed..5a34a1ce 100644 --- a/src/demux/demux.c +++ b/src/demux/demux.c @@ -75,6 +75,7 @@ struct WebPDemuxer { Frame* frames_; Frame** frames_tail_; Chunk* chunks_; // non-image chunks + Chunk** chunks_tail_; }; typedef enum { @@ -179,10 +180,9 @@ static WEBP_INLINE uint32_t ReadLE32(MemBuffer* const mem) { // Secondary chunk parsing static void AddChunk(WebPDemuxer* const dmux, Chunk* const chunk) { - Chunk** c = &dmux->chunks_; - while (*c != NULL) c = &(*c)->next_; - *c = chunk; + *dmux->chunks_tail_ = chunk; chunk->next_ = NULL; + dmux->chunks_tail_ = &chunk->next_; } // Add a frame to the end of the list, ensuring the last frame is complete. @@ -697,6 +697,7 @@ static void InitDemux(WebPDemuxer* const dmux, const MemBuffer* const mem) { dmux->canvas_width_ = -1; dmux->canvas_height_ = -1; dmux->frames_tail_ = &dmux->frames_; + dmux->chunks_tail_ = &dmux->chunks_; dmux->mem_ = *mem; }