[poppler] poppler/JPEG2000Stream.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Sat Nov 29 11:18:36 PST 2008


 poppler/JPEG2000Stream.cc |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

New commits:
commit 5f4fedfae6098e25644ffe5d4b1ed0bac043841d
Author: Albert Astals Cid <aacid at kde.org>
Date:   Sat Nov 29 19:51:27 2008 +0100

    Use the Length specified in the Stream as initial bufSize
    
    This is a optimization to save a few reallocations, if the Length value is incorrect it will still work

diff --git a/poppler/JPEG2000Stream.cc b/poppler/JPEG2000Stream.cc
index 47908fb..f3f0f9e 100644
--- a/poppler/JPEG2000Stream.cc
+++ b/poppler/JPEG2000Stream.cc
@@ -53,7 +53,13 @@ int JPXStream::getChar() {
 
 void JPXStream::init()
 {
+  Object oLen;
+  if (getDict()) getDict()->lookup("Length", &oLen);
+
   int bufSize = BUFFER_INCREASE;
+  if (oLen.isInt()) bufSize = oLen.getInt();
+  oLen.free();
+
   unsigned char *buf = (unsigned char*)gmallocn(bufSize, sizeof(unsigned char));
   int index = 0;
 
@@ -61,13 +67,13 @@ void JPXStream::init()
   int c = str->getChar();
   while(c != EOF)
   {
-    buf[index] = c;
-    ++index;
     if (index >= bufSize)
     {
       bufSize += BUFFER_INCREASE;
       buf = (unsigned char*)greallocn(buf, bufSize, sizeof(unsigned char));
     }
+    buf[index] = c;
+    ++index;
     c = str->getChar();
   }
 


More information about the poppler mailing list