[poppler] poppler/goo: GooHash.cc, 1.2, 1.3 GooHash.h, 1.1.1.1, 1.2 GooList.cc, 1.2, 1.3 GooList.h, 1.1.1.1, 1.2 GooString.cc, 1.1.1.1, 1.2 GooString.h, 1.1.1.1, 1.2 gmem.c, 1.3, 1.4

Brad Hards bradh at freedesktop.org
Sun Aug 28 19:43:20 EST 2005


Update of /cvs/poppler/poppler/goo
In directory gabe:/tmp/cvs-serv2305/goo

Modified Files:
	GooHash.cc GooHash.h GooList.cc GooList.h GooString.cc 
	GooString.h gmem.c 
Log Message:
Merge the Goo* improvements from xpdf 3.0.1. This change is based on
martink's work (7-xpdf-3.01-goo-improvements.patch), with some tweaking
by me.



Index: GooHash.cc
===================================================================
RCS file: /cvs/poppler/poppler/goo/GooHash.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- GooHash.cc	28 Aug 2005 09:31:53 -0000	1.2
+++ GooHash.cc	28 Aug 2005 09:43:18 -0000	1.3
@@ -101,6 +101,30 @@
   ++len;
 }
 
+void GooHash::replace(GooString *key, void *val) {
+  GooHashBucket *p;
+  int h;
+
+  if ((p = find(key, &h))) {
+    p->val.p = val;
+    delete key;
+  } else {
+    add(key, val);
+  }
+}
+
+void GooHash::replace(GooString *key, int val) {
+  GooHashBucket *p;
+  int h;
+
+  if ((p = find(key, &h))) {
+    p->val.i = val;
+    delete key;
+  } else {
+    add(key, val);
+  }
+}
+
 void *GooHash::lookup(GooString *key) {
   GooHashBucket *p;
   int h;

Index: GooHash.h
===================================================================
RCS file: /cvs/poppler/poppler/goo/GooHash.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- GooHash.h	3 Mar 2005 19:45:58 -0000	1.1.1.1
+++ GooHash.h	28 Aug 2005 09:43:18 -0000	1.2
@@ -28,6 +28,8 @@
   ~GooHash();
   void add(GooString *key, void *val);
   void add(GooString *key, int val);
+  void replace(GooString *key, void *val);
+  void replace(GooString *key, int val);
   void *lookup(GooString *key);
   int lookupInt(GooString *key);
   void *lookup(char *key);

Index: GooList.cc
===================================================================
RCS file: /cvs/poppler/poppler/goo/GooList.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- GooList.cc	28 Aug 2005 09:31:53 -0000	1.2
+++ GooList.cc	28 Aug 2005 09:43:18 -0000	1.3
@@ -12,6 +12,7 @@
 #pragma implementation
 #endif
 
+#include <stdlib.h>
 #include <string.h>
 #include "gmem.h"
 #include "GooList.h"
@@ -81,6 +82,10 @@
   return p;
 }
 
+void GooList::sort(int (*cmp)(const void *obj1, const void *obj2)) {
+  qsort(data, length, sizeof(void *), cmp);
+}
+
 void GooList::expand() {
   size += (inc > 0) ? inc : size;
   data = (void **)greallocn(data, size, sizeof(void*));

Index: GooList.h
===================================================================
RCS file: /cvs/poppler/poppler/goo/GooList.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- GooList.h	3 Mar 2005 19:45:58 -0000	1.1.1.1
+++ GooList.h	28 Aug 2005 09:43:18 -0000	1.2
@@ -56,6 +56,11 @@
   // Assumes 0 <= i < length.
   void *del(int i);
 
+  // Sort the list accoring to the given comparison function.
+  // NB: this sorts an array of pointers, so the pointer args need to
+  // be double-dereferenced.
+  void sort(int (*cmp)(const void *ptr1, const void *ptr2));
+
   //----- control
 
   // Set allocation increment to <inc>.  If inc > 0, that many

Index: GooString.cc
===================================================================
RCS file: /cvs/poppler/poppler/goo/GooString.cc,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- GooString.cc	3 Mar 2005 19:45:58 -0000	1.1.1.1
+++ GooString.cc	28 Aug 2005 09:43:18 -0000	1.2
@@ -35,7 +35,12 @@
     s = new char[size(length1)];
   } else if (size(length1) != size(length)) {
     s1 = new char[size(length1)];
-    memcpy(s1, s, length + 1);
+    if (length1 < length) {
+      memcpy(s1, s, length1);
+      s1[length1] = '\0';
+    } else {
+      memcpy(s1, s, length + 1);
+    }
     delete[] s;
     s = s1;
   }
@@ -234,3 +239,81 @@
   }
   return this;
 }
+
+int GooString::cmp(GooString *str) {
+  int n1, n2, i, x;
+  char *p1, *p2;
+
+  n1 = length;
+  n2 = str->length;
+  for (i = 0, p1 = s, p2 = str->s; i < n1 && i < n2; ++i, ++p1, ++p2) {
+    x = *p1 - *p2;
+    if (x != 0) {
+      return x;
+    }
+  }
+  return n1 - n2;
+}
+
+int GooString::cmpN(GooString *str, int n) {
+  int n1, n2, i, x;
+  char *p1, *p2;
+
+  n1 = length;
+  n2 = str->length;
+  for (i = 0, p1 = s, p2 = str->s;
+       i < n1 && i < n2 && i < n;
+       ++i, ++p1, ++p2) {
+    x = *p1 - *p2;
+    if (x != 0) {
+      return x;
+    }
+  }
+  if (i == n) {
+    return 0;
+  }
+  return n1 - n2;
+}
+
+int GooString::cmp(const char *sA) {
+  int n1, i, x;
+  const char *p1, *p2;
+
+  n1 = length;
+  for (i = 0, p1 = s, p2 = sA; i < n1 && *p2; ++i, ++p1, ++p2) {
+    x = *p1 - *p2;
+    if (x != 0) {
+      return x;
+    }
+  }
+  if (i < n1) {
+    return 1;
+  }
+  if (*p2) {
+    return -1;
+  }
+  return 0;
+}
+
+int GooString::cmpN(const char *sA, int n) {
+  int n1, i, x;
+  const char *p1, *p2;
+
+  n1 = length;
+  for (i = 0, p1 = s, p2 = sA; i < n1 && *p2 && i < n; ++i, ++p1, ++p2) {
+    x = *p1 - *p2;
+    if (x != 0) {
+      return x;
+    }
+  }
+  if (i == n) {
+    return 0;
+  }
+  if (i < n1) {
+    return 1;
+  }
+  if (*p2) {
+    return -1;
+  }
+  return 0;
+}

Index: GooString.h
===================================================================
RCS file: /cvs/poppler/poppler/goo/GooString.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- GooString.h	3 Mar 2005 19:45:58 -0000	1.1.1.1
+++ GooString.h	28 Aug 2005 09:43:18 -0000	1.2
@@ -15,8 +15,6 @@
 #pragma interface
 #endif
 
-#include <string.h>
-
 class GooString {
 public:
 
@@ -81,11 +79,10 @@
   GooString *lowerCase();
 
   // Compare two strings:  -1:<  0:=  +1:>
-  // These functions assume the strings do not contain null characters.
-  int cmp(GooString *str) { return strcmp(s, str->getCString()); }
-  int cmpN(GooString *str, int n) { return strncmp(s, str->getCString(), n); }
-  int cmp(const char *sA) { return strcmp(s, sA); }
-  int cmpN(const char *sA, int n) { return strncmp(s, sA, n); }
+  int cmp(GooString *str);
+  int cmpN(GooString *str, int n);
+  int cmp(const char *sA);
+  int cmpN(const char *sA, int n);
 
 private:
 

Index: gmem.c
===================================================================
RCS file: /cvs/poppler/poppler/goo/gmem.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- gmem.c	27 Aug 2005 08:43:43 -0000	1.3
+++ gmem.c	28 Aug 2005 09:43:18 -0000	1.4
@@ -50,6 +50,7 @@
 
 static int gMemIndex = 0;
 static int gMemAlloc = 0;
+static int gMemInUse = 0;
 
 #endif /* DEBUG_MEM */
 
@@ -78,6 +79,7 @@
   hdr->next = gMemList[lst];
   gMemList[lst] = hdr;
   ++gMemAlloc;
+  gMemInUse += size;
   for (p = (unsigned long *)data; p <= trl; ++p)
     *p = gMemDeadVal;
   return data;
@@ -178,6 +180,7 @@
       else
 	gMemList[lst] = hdr->next;
       --gMemAlloc;
+      gMemInUse -= hdr->size;
       size = gMemDataSize(hdr->size);
       trl = (unsigned long *)((char *)hdr + gMemHdrSize + size);
       if (*trl != gMemDeadVal) {



More information about the poppler mailing list