Index: pykota/trunk/pykota/pdlanalyzer.py
===================================================================
--- pykota/trunk/pykota/pdlanalyzer.py (revision 1570)
+++ pykota/trunk/pykota/pdlanalyzer.py (revision 1572)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.16  2004/06/26 15:31:00  jalet
+# mmap reintroduced in PCL5 parser
+#
 # Revision 1.15  2004/06/26 14:14:31  jalet
 # Now uses Psyco if it is available
@@ -77,5 +80,5 @@
 import struct
 import tempfile
-import popen2
+import mmap
     
 KILOBYTE = 1024    
@@ -122,31 +125,4 @@
         self.infile = infile
         
-    def skip(self, nb) :    
-        """Reads a new datablock."""
-        newpos = self.pos + nb
-        if newpos >= self.len :
-            oldlen = self.len
-            self.data = self.infile.read(MEGABYTE)
-            self.len = len(self.data)
-            if not self.len :
-                return
-            self.pos = newpos - oldlen
-        else :    
-            self.pos = newpos
-        
-    def readone(self) :
-        """Reads a new byte."""
-        if self.pos < self.len :
-            char = self.data[self.pos]
-        else :    
-            self.data = self.infile.read(MEGABYTE)
-            self.len = len(self.data)
-            self.pos = 0
-            if not self.len :    
-                return
-            char = self.data[0]
-        self.pos += 1    
-        return char
-        
     def getJobSize(self) :     
         """Count pages in a PCL5 document."""
@@ -165,4 +141,6 @@
         # http://h20000.www2.hp.com/bc/docs/support/SupportManual/bpl13205/bpl13205.pdf 
         #
+        infileno = self.infile.fileno()
+        minfile = mmap.mmap(infileno, os.fstat(infileno).st_size, access=mmap.ACCESS_READ)
         tagsends = { "&n" : "W", 
                      "&b" : "W", 
@@ -180,68 +158,66 @@
                      "&a" : "G",
                    }  
-        self.data = []             
-        self.pos = self.len = 0
         pagecount = resets = ejects = backsides = 0
         tag = None
         copies = {}
-        while 1 :
-            char = self.readone()
-            if not char :       # EOF ?
-                break   
-            if char == "\014" :    
-                pagecount += 1
-            elif char == "\033" :    
-                #
-                #     <ESC>*b###W -> Start of a raster data row/block
-                #     <ESC>*b###V -> Start of a raster data plane
-                #     <ESC>*c###W -> Start of a user defined pattern
-                #     <ESC>*i###W -> Start of a viewing illuminant block
-                #     <ESC>*l###W -> Start of a color lookup table
-                #     <ESC>*m###W -> Start of a download dither matrix block
-                #     <ESC>*v###W -> Start of a configure image data block
-                #     <ESC>(s###W -> Start of a characters description block
-                #     <ESC>)s###W -> Start of a fonts description block
-                #     <ESC>(f###W -> Start of a symbol set block
-                #     <ESC>&b###W -> Start of configuration data block
-                #     <ESC>&l###X -> Number of copies for current page
-                #     <ESC>&n###W -> Starts an alphanumeric string ID block
-                #     <ESC>&p###X -> Start of a non printable characters block
-                #     <ESC>&a2G -> Back side when duplex mode as generated by rastertohp
-                #     <ESC>&l0H -> Eject if NumPlanes > 1, as generated by rastertohp
-                #
-                tagstart = self.readone()
-                if tagstart in "E9=YZ" : # one byte PCL tag
-                    if tagstart == "E" :
-                        resets += 1
-                    continue             # skip to next tag
-                tag = tagstart + self.readone()
-                try :
-                    tagend = tagsends[tag]
-                except KeyError :    
-                    pass    # Unsupported PCL tag
-                else :    
-                    # Now read the numeric argument
-                    size = 0
-                    while 1 :
-                        char = self.readone()
-                        if not char.isdigit() :
-                            break
-                        size = (size * 10) + int(char)    
-                    if char in tagend :    
-                        if (tag == "&l") and (char == "X") : # copies for current page
-                            copies[pagecount] = size
-                        elif (tag == "&l") and (char == "H") and (size == 0) :    
-                            ejects += 1         # Eject 
-                        elif (tag == "&a") and (size == 2) :
-                            backsides += 1      # Back side in duplex mode
-                        else :    
-                            # doing a read will prevent the seek 
-                            # for unseekable streams. 
-                            # we just ignore the block anyway.
-                            if tag == "&n" : 
-                                # we have to take care of the operation id byte
-                                # which is before the string itself
-                                size += 1
-                            self.skip(size)
+        pos = 0
+        try :
+            while 1 :
+                char = minfile[pos] ; pos += 1
+                if char == "\014" :    
+                    pagecount += 1
+                elif char == "\033" :    
+                    #
+                    #     <ESC>*b###W -> Start of a raster data row/block
+                    #     <ESC>*b###V -> Start of a raster data plane
+                    #     <ESC>*c###W -> Start of a user defined pattern
+                    #     <ESC>*i###W -> Start of a viewing illuminant block
+                    #     <ESC>*l###W -> Start of a color lookup table
+                    #     <ESC>*m###W -> Start of a download dither matrix block
+                    #     <ESC>*v###W -> Start of a configure image data block
+                    #     <ESC>(s###W -> Start of a characters description block
+                    #     <ESC>)s###W -> Start of a fonts description block
+                    #     <ESC>(f###W -> Start of a symbol set block
+                    #     <ESC>&b###W -> Start of configuration data block
+                    #     <ESC>&l###X -> Number of copies for current page
+                    #     <ESC>&n###W -> Starts an alphanumeric string ID block
+                    #     <ESC>&p###X -> Start of a non printable characters block
+                    #     <ESC>&a2G -> Back side when duplex mode as generated by rastertohp
+                    #     <ESC>&l0H -> Eject if NumPlanes > 1, as generated by rastertohp
+                    #
+                    tagstart = minfile[pos] ; pos += 1
+                    if tagstart in "E9=YZ" : # one byte PCL tag
+                        if tagstart == "E" :
+                            resets += 1
+                        continue             # skip to next tag
+                    tag = tagstart + minfile[pos] ; pos += 1
+                    try :
+                        tagend = tagsends[tag]
+                    except KeyError :    
+                        pass    # Unsupported PCL tag
+                    else :    
+                        # Now read the numeric argument
+                        size = 0
+                        while 1 :
+                            char = minfile[pos] ; pos += 1
+                            if not char.isdigit() :
+                                break
+                            size = (size * 10) + int(char)    
+                        if char in tagend :    
+                            if (tag == "&l") and (char == "X") : # copies for current page
+                                copies[pagecount] = size
+                            elif (tag == "&l") and (char == "H") and (size == 0) :    
+                                ejects += 1         # Eject 
+                            elif (tag == "&a") and (size == 2) :
+                                backsides += 1      # Back side in duplex mode
+                            else :    
+                                # we just ignore the block.
+                                if tag == "&n" : 
+                                    # we have to take care of the operation id byte
+                                    # which is before the string itself
+                                    size += 1
+                                pos += size    
+        except IndexError : # EOF ?
+            minfile.close() # reached EOF
                             
         # if pagecount is still 0, we will use the number
Index: pykota/trunk/NEWS
===================================================================
--- pykota/trunk/NEWS (revision 1570)
+++ pykota/trunk/NEWS (revision 1572)
@@ -24,7 +24,12 @@
     - 1.19alpha27 :
     
+        - Reintroduced the use of mmap in PCL5 parser : this speedups
+          PCL5 parsing by almost 4 times.
+          This 4x with the 3x below give us in fact a twelvefold increase
+          in performance for PCL5 parsing !
+          
         - The Python accelerator Psyco is now used if available
           in the generic PDL parser : it speedups PCL5 parsing by
-          almost three times automagically.
+          almost three times automagically. 
           
     - 1.19alpha26 :
