[poppler] poppler/poppler: PSTokenizer.cc, 1.1.1.1, 1.2 PSTokenizer.h, 1.1.1.1, 1.2

Albert Astals Cid aacid at kemper.freedesktop.org
Sat Dec 23 05:12:16 PST 2006


Update of /cvs/poppler/poppler/poppler
In directory kemper:/tmp/cvs-serv24015/poppler

Modified Files:
	PSTokenizer.cc PSTokenizer.h 
Log Message:
        * poppler/PSTokenizer.cc: Enhance PSTokenizer::getToken performance.
        Patch by Scott Turner <scotty1024 at mac.com>. In a random pdf i tested
        the patchs improves PSTokenizer::getToken performance by 15%


Index: PSTokenizer.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/PSTokenizer.cc,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- PSTokenizer.cc	3 Mar 2005 19:46:03 -0000	1.1.1.1
+++ PSTokenizer.cc	23 Dec 2006 13:12:14 -0000	1.2
@@ -55,7 +55,7 @@
   int c;
   int i;
 
-  // skip whitespace and comments
+  // skip leading whitespace and comments
   comment = gFalse;
   while (1) {
     if ((c = getChar()) == EOF) {
@@ -74,16 +74,19 @@
     }
   }
 
+  // Reserve room for terminating '\0'
+  size--;
+
   // read a token
   i = 0;
   buf[i++] = c;
   if (c == '(') {
     backslash = gFalse;
     while ((c = lookChar()) != EOF) {
-      if (i < size - 1) {
+      consumeChar();
+      if (i < size) {
 	buf[i++] = c;
       }
-      getChar();
       if (c == '\\') {
 	backslash = gTrue;
       } else if (!backslash && c == ')') {
@@ -94,8 +97,8 @@
     }
   } else if (c == '<') {
     while ((c = lookChar()) != EOF) {
-      getChar();
-      if (i < size - 1) {
+      consumeChar();
+      if (i < size) {
 	buf[i++] = c;
       }
       if (c == '>') {
@@ -104,13 +107,15 @@
     }
   } else if (c != '[' && c != ']') {
     while ((c = lookChar()) != EOF && !specialChars[c]) {
-      getChar();
-      if (i < size - 1) {
+      consumeChar();
+      if (i < size) {
 	buf[i++] = c;
       }
     }
   }
+  // Zero terminate token string
   buf[i] = '\0';
+  // Return length of token
   *length = i;
 
   return gTrue;
@@ -123,13 +128,17 @@
   return charBuf;
 }
 
+void PSTokenizer::consumeChar() {
+  charBuf = -1;
+}
+
 int PSTokenizer::getChar() {
-  int c;
+  int c = charBuf;
 
-  if (charBuf < 0) {
-    charBuf = (*getCharFunc)(data);
+  if (c < 0) {
+    c = (*getCharFunc)(data);
+  } else {
+    charBuf = -1;
   }
-  c = charBuf;
-  charBuf = -1;
   return c;
 }

Index: PSTokenizer.h
===================================================================
RCS file: /cvs/poppler/poppler/poppler/PSTokenizer.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- PSTokenizer.h	3 Mar 2005 19:46:01 -0000	1.1.1.1
+++ PSTokenizer.h	23 Dec 2006 13:12:14 -0000	1.2
@@ -29,6 +29,7 @@
 private:
 
   int lookChar();
+  void consumeChar();
   int getChar();
 
   int (*getCharFunc)(void *);



More information about the poppler mailing list