Commit 7905adaa authored by Albert Astals Cid's avatar Albert Astals Cid

* 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.
parent 4da7c90a
2006-09-03 Albert Astals Cid <aacid@kde.org>
* 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.
2006-08-25 Albert Astals Cid <aacid@kde.org>
* qt4/src/poppler-private.h: Init m_fontInfoScanner to NULL. Discovered by
......
......@@ -41,7 +41,7 @@ Dict::~Dict() {
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 @@ void Dict::add(const UGooString &key, Object *val) {
}
entries = (DictEntry *)greallocn(entries, size, sizeof(DictEntry));
}
entries[length].key = new UGooString(key);
entries[length].key = key;
entries[length].val = *val;
++length;
}
......
......@@ -14,8 +14,8 @@
#endif
#include "Object.h"
#include "UGooString.h"
class UGooString;
//------------------------------------------------------------------------
// Dict
//------------------------------------------------------------------------
......@@ -42,7 +42,14 @@ public:
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);
......
......@@ -107,6 +107,10 @@ public:
// 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 @@ public:
// 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 int Object::dictGetLength()
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); }
......
......@@ -39,7 +39,6 @@ Parser::~Parser() {
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 @@ Object *Parser::getObj(Object *obj,
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 @@ Object *Parser::getObj(Object *obj,
// 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 @@ void Parser::shift(int objNum) {
inlineImg = 1;
}
buf1.free();
buf1 = buf2;
buf2.shallowCopy(&buf1);
if (inlineImg > 0) // don't buffer inline image data
buf2.initNull();
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment