mozilla/pdf.js — pull request #5445 by CodingFabian (2014-10-26 16:06:43+00:00)
Title: Fixes caching of inline images during parsing.

As described in #5444, the evaluator will perform identity checking of
paintImageMaskXObjects to decide if it can use
paintImageMaskXObjectRepeat instead of paintImageMaskXObjectGroup.

This can only ever work if the entry is a cache hit. However the
previous caching implementation was doing a "lazy" caching, which would
only consider a image cache-worthy if it is repeated.
Only then the repeated instance would be cached.
As a result of this the sequence of identical images A B C D would be
seen as A B B B by the evaluator, which prevents using the "repeat"
optimization.

Also the previous cache implementation was only checking the last used
image.
Thus the sequence A1 B1 A2 B2 A3 B3 would be 6 instances of images, even
when there are only two different ones.

The new implementation drops the "lazy" init of the cache. The threshold
for enabling an image to be cached is rather small, so the potential waste
in storage and adler32 calculation is pretty low.
Also this implementation will now keep hold of any cachable images. Not
only the last seen image.

The two examples from above would now be A A A A and A1 B1 A1 B1 A1 B1,
which not only saves temporary storage, but also prevents computing
identical masks over and over again (which is the main performance impact
of #2618)