[poppler] poppler/poppler: Dict.cc, 1.4, 1.5 Dict.h, 1.3,
1.4 Object.h, 1.2, 1.3 Parser.cc, 1.5, 1.6
Albert Astals Cid
aacid at kemper.freedesktop.org
Sun Sep 3 02:27:23 PDT 2006
Update of /cvs/poppler/poppler/poppler
In directory kemper:/tmp/cvs-serv15110/poppler
Modified Files:
Dict.cc Dict.h Object.h Parser.cc
Log Message:
* poppler/Dict.cc:
* poppler/Dict.h:
* poppler/Object.h:
* poppler/Parser.cc: Patch by Krzysztof Kowalczyk to increase speed by
means of doing less copies between objects. See bug 8112 for more
information.
Index: Dict.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/Dict.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Dict.cc 18 Jan 2006 22:32:13 -0000 1.4
+++ Dict.cc 3 Sep 2006 09:27:21 -0000 1.5
@@ -41,7 +41,7 @@
gfree(entries);
}
-void Dict::add(const UGooString &key, Object *val) {
+void Dict::addOwnKeyVal(UGooString *key, Object *val) {
if (length == size) {
if (length == 0) {
size = 8;
@@ -50,7 +50,7 @@
}
entries = (DictEntry *)greallocn(entries, size, sizeof(DictEntry));
}
- entries[length].key = new UGooString(key);
+ entries[length].key = key;
entries[length].val = *val;
++length;
}
Index: Dict.h
===================================================================
RCS file: /cvs/poppler/poppler/poppler/Dict.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Dict.h 18 Jan 2006 22:32:13 -0000 1.3
+++ Dict.h 3 Sep 2006 09:27:21 -0000 1.4
@@ -14,8 +14,8 @@
#endif
#include "Object.h"
+#include "UGooString.h"
-class UGooString;
//------------------------------------------------------------------------
// Dict
//------------------------------------------------------------------------
@@ -42,7 +42,14 @@
int getLength() { return length; }
// Add an entry
- void add(const UGooString &key, Object *val);
+ void addOwnKeyVal(UGooString *key, Object *val);
+ // FIXME: should also be renamed to addOwnVal()
+ void add(const UGooString &key, Object *val) {
+ addOwnKeyVal(new UGooString(key), val);
+ }
+ void addOwnVal(const char *key, Object *val) {
+ addOwnKeyVal(new UGooString(key), val);
+ }
// Check if dictionary is of specified type.
GBool is(char *type);
Index: Object.h
===================================================================
RCS file: /cvs/poppler/poppler/poppler/Object.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Object.h 18 Jan 2006 22:32:13 -0000 1.2
+++ Object.h 3 Sep 2006 09:27:21 -0000 1.3
@@ -107,6 +107,10 @@
// Copy an object.
Object *copy(Object *obj);
+ Object *shallowCopy(Object *obj) {
+ *obj = *this;
+ return obj;
+ }
// If object is a Ref, fetch and return the referenced object.
// Otherwise, return a copy of the object.
@@ -164,7 +168,9 @@
// Dict accessors.
int dictGetLength();
+ void dictAddOwnKeyVal(UGooString *key, Object *val);
void dictAdd(const UGooString &key, Object *val);
+ void dictAddOwnVal(const char *key, Object *val);
GBool dictIs(char *dictType);
Object *dictLookup(const UGooString &key, Object *obj);
Object *dictLookupNF(const UGooString &key, Object *obj);
@@ -242,6 +248,12 @@
inline void Object::dictAdd(const UGooString &key, Object *val)
{ dict->add(key, val); }
+inline void Object::dictAddOwnVal(const char *key, Object *val)
+ { dict->addOwnVal(key, val); }
+
+inline void Object::dictAddOwnKeyVal(UGooString *key, Object *val)
+ { dict->addOwnKeyVal(key, val); }
+
inline GBool Object::dictIs(char *dictType)
{ return dict->is(dictType); }
Index: Parser.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/Parser.cc,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Parser.cc 18 Jan 2006 22:32:13 -0000 1.5
+++ Parser.cc 3 Sep 2006 09:27:21 -0000 1.6
@@ -39,7 +39,6 @@
Object *Parser::getObj(Object *obj,
Guchar *fileKey, int keyLength,
int objNum, int objGen) {
- char *key;
Stream *str;
Object obj2;
int num;
@@ -76,14 +75,14 @@
error(getPos(), "Dictionary key must be a name object");
shift();
} else {
- key = copyString(buf1.getName());
+ // buf1 might go away in shift(), so construct the key
+ UGooString *key = new UGooString(buf1.getName());
shift();
if (buf1.isEOF() || buf1.isError()) {
gfree(key);
break;
}
- obj->dictAdd(key, getObj(&obj2, fileKey, keyLength, objNum, objGen));
- gfree(key);
+ obj->dictAddOwnKeyVal(key, getObj(&obj2, fileKey, keyLength, objNum, objGen));
}
}
if (buf1.isEOF())
@@ -130,7 +129,11 @@
// simple object
} else {
- buf1.copy(obj);
+ // avoid re-allocating memory for complex objects like strings by
+ // shallow copy of <buf1> to <obj> and nulling <buf1> so that
+ // subsequent buf1.free() won't free this memory
+ buf1.shallowCopy(obj);
+ buf1.initNull();
shift();
}
@@ -208,7 +211,7 @@
inlineImg = 1;
}
buf1.free();
- buf1 = buf2;
+ buf2.shallowCopy(&buf1);
if (inlineImg > 0) // don't buffer inline image data
buf2.initNull();
else
More information about the poppler
mailing list