summaryrefslogtreecommitdiff
path: root/lodepng.cpp
diff options
context:
space:
mode:
authorLode <lvandeve@gmail.com>2015-04-19 19:15:05 +0200
committerLode <lvandeve@gmail.com>2015-04-19 19:15:05 +0200
commit0bceffb6eca66fe405c59f5c58c6ef2ff1be4add (patch)
tree32ea984b37ec369042d8c6b6b1ec37d2a28a5326 /lodepng.cpp
parent768e2e1ba48f539d1d32cfbca432b5005d931a48 (diff)
small optimization
Diffstat (limited to 'lodepng.cpp')
-rw-r--r--lodepng.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/lodepng.cpp b/lodepng.cpp
index e911c40..326b952 100644
--- a/lodepng.cpp
+++ b/lodepng.cpp
@@ -1168,12 +1168,14 @@ static unsigned inflateHuffmanBlock(ucvector* out, const unsigned char* in, size
backward = start - distance;
if(!ucvector_resize(out, (*pos) + length)) ERROR_BREAK(83 /*alloc fail*/);
- for(forward = 0; forward < length; ++forward)
- {
- out->data[(*pos)] = out->data[backward];
- ++(*pos);
- ++backward;
- if(backward >= start) backward = start - distance;
+ if (distance < length) {
+ for(forward = 0; forward < length; ++forward)
+ {
+ out->data[(*pos)++] = out->data[backward++];
+ }
+ } else {
+ memcpy(out->data + *pos, out->data + backward, length);
+ *pos += length;
}
}
else if(code_ll == 256)