mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Performance: remove Members indirection for QPDFObjectHandle
This commit is contained in:
parent
31092dc66b
commit
89f19b7099
@ -1,3 +1,9 @@
|
||||
2020-04-02 Jay Berkenbilt <ejb@ql.org>
|
||||
|
||||
* Remove Members class indirection for QPDFObjectHandle. Those are
|
||||
copied and assigned too often, and that change caused a very
|
||||
substantial performance hit.
|
||||
|
||||
2020-03-31 Jay Berkenbilt <ejb@ql.org>
|
||||
|
||||
* When detecting unreferenced images during page splitting, if any
|
||||
|
@ -251,10 +251,10 @@ class QPDFObjectHandle
|
||||
QPDF_DLL
|
||||
QPDFObjectHandle();
|
||||
QPDF_DLL
|
||||
QPDFObjectHandle(QPDFObjectHandle const&);
|
||||
QPDFObjectHandle(QPDFObjectHandle const&) = default;
|
||||
QPDF_DLL
|
||||
QPDFObjectHandle&
|
||||
operator=(QPDFObjectHandle const&);
|
||||
operator=(QPDFObjectHandle const&) = default;
|
||||
QPDF_DLL
|
||||
bool isInitialized() const;
|
||||
|
||||
@ -957,7 +957,7 @@ class QPDFObjectHandle
|
||||
static PointerHolder<QPDFObject> getObject(QPDFObjectHandle& o)
|
||||
{
|
||||
o.dereference();
|
||||
return o.m->obj;
|
||||
return o.obj;
|
||||
}
|
||||
};
|
||||
friend class ObjAccessor;
|
||||
@ -1077,29 +1077,16 @@ class QPDFObjectHandle
|
||||
std::string const& description, std::string& all_description);
|
||||
static void warn(QPDF*, QPDFExc const&);
|
||||
|
||||
class Members
|
||||
{
|
||||
friend class ObjAccessor;
|
||||
friend class QPDFObjectHandle;
|
||||
|
||||
public:
|
||||
QPDF_DLL
|
||||
~Members();
|
||||
|
||||
private:
|
||||
Members();
|
||||
Members(QPDF* qpdf, int objid, int generation);
|
||||
Members(QPDFObject* data);
|
||||
|
||||
bool initialized;
|
||||
|
||||
// Moving members of QPDFObjectHandle into a smart pointer incurs
|
||||
// a substantial performance penalty since QPDFObjectHandle
|
||||
// objects are copied around so frequently.
|
||||
QPDF* qpdf;
|
||||
int objid; // 0 for direct object
|
||||
int generation;
|
||||
PointerHolder<QPDFObject> obj;
|
||||
bool reserved;
|
||||
};
|
||||
PointerHolder<Members> m;
|
||||
};
|
||||
|
||||
#endif // QPDFOBJECTHANDLE_HH
|
||||
|
@ -135,11 +135,7 @@ QPDFObjectHandle::ParserCallbacks::terminateParsing()
|
||||
throw TerminateParsing();
|
||||
}
|
||||
|
||||
QPDFObjectHandle::Members::~Members()
|
||||
{
|
||||
}
|
||||
|
||||
QPDFObjectHandle::Members::Members() :
|
||||
QPDFObjectHandle::QPDFObjectHandle() :
|
||||
initialized(false),
|
||||
qpdf(0),
|
||||
objid(0),
|
||||
@ -148,7 +144,7 @@ QPDFObjectHandle::Members::Members() :
|
||||
{
|
||||
}
|
||||
|
||||
QPDFObjectHandle::Members::Members(QPDF* qpdf, int objid, int generation) :
|
||||
QPDFObjectHandle::QPDFObjectHandle(QPDF* qpdf, int objid, int generation) :
|
||||
initialized(true),
|
||||
qpdf(qpdf),
|
||||
objid(objid),
|
||||
@ -157,7 +153,7 @@ QPDFObjectHandle::Members::Members(QPDF* qpdf, int objid, int generation) :
|
||||
{
|
||||
}
|
||||
|
||||
QPDFObjectHandle::Members::Members(QPDFObject* data) :
|
||||
QPDFObjectHandle::QPDFObjectHandle(QPDFObject* data) :
|
||||
initialized(true),
|
||||
qpdf(0),
|
||||
objid(0),
|
||||
@ -167,38 +163,6 @@ QPDFObjectHandle::Members::Members(QPDFObject* data) :
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QPDFObjectHandle::QPDFObjectHandle() :
|
||||
m(new Members)
|
||||
{
|
||||
}
|
||||
|
||||
QPDFObjectHandle::QPDFObjectHandle(QPDFObjectHandle const& rhs) :
|
||||
m(new Members)
|
||||
{
|
||||
*m = *rhs.m;
|
||||
}
|
||||
|
||||
QPDFObjectHandle&
|
||||
QPDFObjectHandle::operator=(QPDFObjectHandle const& rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
*m = *rhs.m;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
QPDFObjectHandle::QPDFObjectHandle(QPDF* qpdf, int objid, int generation) :
|
||||
m(new Members(qpdf, objid, generation))
|
||||
{
|
||||
}
|
||||
|
||||
QPDFObjectHandle::QPDFObjectHandle(QPDFObject* data) :
|
||||
m(new Members(data))
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
QPDFObjectHandle::releaseResolved()
|
||||
{
|
||||
@ -208,14 +172,14 @@ QPDFObjectHandle::releaseResolved()
|
||||
// destruction. See comments in QPDF::~QPDF().
|
||||
if (isIndirect())
|
||||
{
|
||||
if (this->m->obj.getPointer())
|
||||
if (this->obj.getPointer())
|
||||
{
|
||||
this->m->obj = 0;
|
||||
this->obj = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QPDFObject::ObjAccessor::releaseResolved(this->m->obj.getPointer());
|
||||
QPDFObject::ObjAccessor::releaseResolved(this->obj.getPointer());
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,16 +198,16 @@ QPDFObjectHandle::setObjectDescriptionFromInput(
|
||||
bool
|
||||
QPDFObjectHandle::isInitialized() const
|
||||
{
|
||||
return this->m->initialized;
|
||||
return this->initialized;
|
||||
}
|
||||
|
||||
QPDFObject::object_type_e
|
||||
QPDFObjectHandle::getTypeCode()
|
||||
{
|
||||
if (this->m->initialized)
|
||||
if (this->initialized)
|
||||
{
|
||||
dereference();
|
||||
return this->m->obj->getTypeCode();
|
||||
return this->obj->getTypeCode();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -254,10 +218,10 @@ QPDFObjectHandle::getTypeCode()
|
||||
char const*
|
||||
QPDFObjectHandle::getTypeName()
|
||||
{
|
||||
if (this->m->initialized)
|
||||
if (this->initialized)
|
||||
{
|
||||
dereference();
|
||||
return this->m->obj->getTypeName();
|
||||
return this->obj->getTypeName();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -283,35 +247,35 @@ bool
|
||||
QPDFObjectHandle::isBool()
|
||||
{
|
||||
dereference();
|
||||
return QPDFObjectTypeAccessor<QPDF_Bool>::check(m->obj.getPointer());
|
||||
return QPDFObjectTypeAccessor<QPDF_Bool>::check(obj.getPointer());
|
||||
}
|
||||
|
||||
bool
|
||||
QPDFObjectHandle::isDirectNull() const
|
||||
{
|
||||
return (this->m->initialized && (this->m->objid == 0) &&
|
||||
QPDFObjectTypeAccessor<QPDF_Null>::check(m->obj.getPointer()));
|
||||
return (this->initialized && (this->objid == 0) &&
|
||||
QPDFObjectTypeAccessor<QPDF_Null>::check(obj.getPointer()));
|
||||
}
|
||||
|
||||
bool
|
||||
QPDFObjectHandle::isNull()
|
||||
{
|
||||
dereference();
|
||||
return QPDFObjectTypeAccessor<QPDF_Null>::check(m->obj.getPointer());
|
||||
return QPDFObjectTypeAccessor<QPDF_Null>::check(obj.getPointer());
|
||||
}
|
||||
|
||||
bool
|
||||
QPDFObjectHandle::isInteger()
|
||||
{
|
||||
dereference();
|
||||
return QPDFObjectTypeAccessor<QPDF_Integer>::check(m->obj.getPointer());
|
||||
return QPDFObjectTypeAccessor<QPDF_Integer>::check(obj.getPointer());
|
||||
}
|
||||
|
||||
bool
|
||||
QPDFObjectHandle::isReal()
|
||||
{
|
||||
dereference();
|
||||
return QPDFObjectTypeAccessor<QPDF_Real>::check(m->obj.getPointer());
|
||||
return QPDFObjectTypeAccessor<QPDF_Real>::check(obj.getPointer());
|
||||
}
|
||||
|
||||
bool
|
||||
@ -344,49 +308,49 @@ bool
|
||||
QPDFObjectHandle::isName()
|
||||
{
|
||||
dereference();
|
||||
return QPDFObjectTypeAccessor<QPDF_Name>::check(m->obj.getPointer());
|
||||
return QPDFObjectTypeAccessor<QPDF_Name>::check(obj.getPointer());
|
||||
}
|
||||
|
||||
bool
|
||||
QPDFObjectHandle::isString()
|
||||
{
|
||||
dereference();
|
||||
return QPDFObjectTypeAccessor<QPDF_String>::check(m->obj.getPointer());
|
||||
return QPDFObjectTypeAccessor<QPDF_String>::check(obj.getPointer());
|
||||
}
|
||||
|
||||
bool
|
||||
QPDFObjectHandle::isOperator()
|
||||
{
|
||||
dereference();
|
||||
return QPDFObjectTypeAccessor<QPDF_Operator>::check(m->obj.getPointer());
|
||||
return QPDFObjectTypeAccessor<QPDF_Operator>::check(obj.getPointer());
|
||||
}
|
||||
|
||||
bool
|
||||
QPDFObjectHandle::isInlineImage()
|
||||
{
|
||||
dereference();
|
||||
return QPDFObjectTypeAccessor<QPDF_InlineImage>::check(m->obj.getPointer());
|
||||
return QPDFObjectTypeAccessor<QPDF_InlineImage>::check(obj.getPointer());
|
||||
}
|
||||
|
||||
bool
|
||||
QPDFObjectHandle::isArray()
|
||||
{
|
||||
dereference();
|
||||
return QPDFObjectTypeAccessor<QPDF_Array>::check(m->obj.getPointer());
|
||||
return QPDFObjectTypeAccessor<QPDF_Array>::check(obj.getPointer());
|
||||
}
|
||||
|
||||
bool
|
||||
QPDFObjectHandle::isDictionary()
|
||||
{
|
||||
dereference();
|
||||
return QPDFObjectTypeAccessor<QPDF_Dictionary>::check(m->obj.getPointer());
|
||||
return QPDFObjectTypeAccessor<QPDF_Dictionary>::check(obj.getPointer());
|
||||
}
|
||||
|
||||
bool
|
||||
QPDFObjectHandle::isStream()
|
||||
{
|
||||
dereference();
|
||||
return QPDFObjectTypeAccessor<QPDF_Stream>::check(m->obj.getPointer());
|
||||
return QPDFObjectTypeAccessor<QPDF_Stream>::check(obj.getPointer());
|
||||
}
|
||||
|
||||
bool
|
||||
@ -394,14 +358,14 @@ QPDFObjectHandle::isReserved()
|
||||
{
|
||||
// dereference will clear reserved if this has been replaced
|
||||
dereference();
|
||||
return this->m->reserved;
|
||||
return this->reserved;
|
||||
}
|
||||
|
||||
bool
|
||||
QPDFObjectHandle::isIndirect()
|
||||
{
|
||||
assertInitialized();
|
||||
return (this->m->objid != 0);
|
||||
return (this->objid != 0);
|
||||
}
|
||||
|
||||
bool
|
||||
@ -418,7 +382,7 @@ QPDFObjectHandle::getBoolValue()
|
||||
{
|
||||
if (isBool())
|
||||
{
|
||||
return dynamic_cast<QPDF_Bool*>(m->obj.getPointer())->getVal();
|
||||
return dynamic_cast<QPDF_Bool*>(obj.getPointer())->getVal();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -435,7 +399,7 @@ QPDFObjectHandle::getIntValue()
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
return dynamic_cast<QPDF_Integer*>(m->obj.getPointer())->getVal();
|
||||
return dynamic_cast<QPDF_Integer*>(obj.getPointer())->getVal();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -528,7 +492,7 @@ QPDFObjectHandle::getRealValue()
|
||||
{
|
||||
if (isReal())
|
||||
{
|
||||
return dynamic_cast<QPDF_Real*>(m->obj.getPointer())->getVal();
|
||||
return dynamic_cast<QPDF_Real*>(obj.getPointer())->getVal();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -545,7 +509,7 @@ QPDFObjectHandle::getName()
|
||||
{
|
||||
if (isName())
|
||||
{
|
||||
return dynamic_cast<QPDF_Name*>(m->obj.getPointer())->getName();
|
||||
return dynamic_cast<QPDF_Name*>(obj.getPointer())->getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -562,7 +526,7 @@ QPDFObjectHandle::getStringValue()
|
||||
{
|
||||
if (isString())
|
||||
{
|
||||
return dynamic_cast<QPDF_String*>(m->obj.getPointer())->getVal();
|
||||
return dynamic_cast<QPDF_String*>(obj.getPointer())->getVal();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -577,7 +541,7 @@ QPDFObjectHandle::getUTF8Value()
|
||||
{
|
||||
if (isString())
|
||||
{
|
||||
return dynamic_cast<QPDF_String*>(m->obj.getPointer())->getUTF8Val();
|
||||
return dynamic_cast<QPDF_String*>(obj.getPointer())->getUTF8Val();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -594,7 +558,7 @@ QPDFObjectHandle::getOperatorValue()
|
||||
{
|
||||
if (isOperator())
|
||||
{
|
||||
return dynamic_cast<QPDF_Operator*>(m->obj.getPointer())->getVal();
|
||||
return dynamic_cast<QPDF_Operator*>(obj.getPointer())->getVal();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -609,7 +573,7 @@ QPDFObjectHandle::getInlineImageValue()
|
||||
{
|
||||
if (isInlineImage())
|
||||
{
|
||||
return dynamic_cast<QPDF_InlineImage*>(m->obj.getPointer())->getVal();
|
||||
return dynamic_cast<QPDF_InlineImage*>(obj.getPointer())->getVal();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -626,7 +590,7 @@ QPDFObjectHandle::getArrayNItems()
|
||||
{
|
||||
if (isArray())
|
||||
{
|
||||
return dynamic_cast<QPDF_Array*>(m->obj.getPointer())->getNItems();
|
||||
return dynamic_cast<QPDF_Array*>(obj.getPointer())->getNItems();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -642,7 +606,7 @@ QPDFObjectHandle::getArrayItem(int n)
|
||||
QPDFObjectHandle result;
|
||||
if (isArray() && (n < getArrayNItems()) && (n >= 0))
|
||||
{
|
||||
result = dynamic_cast<QPDF_Array*>(m->obj.getPointer())->getItem(n);
|
||||
result = dynamic_cast<QPDF_Array*>(obj.getPointer())->getItem(n);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -659,7 +623,7 @@ QPDFObjectHandle::getArrayItem(int n)
|
||||
}
|
||||
QPDF* context = 0;
|
||||
std::string description;
|
||||
if (this->m->obj->getDescription(context, description))
|
||||
if (this->obj->getDescription(context, description))
|
||||
{
|
||||
result.setObjectDescription(
|
||||
context,
|
||||
@ -755,7 +719,7 @@ QPDFObjectHandle::getArrayAsVector()
|
||||
std::vector<QPDFObjectHandle> result;
|
||||
if (isArray())
|
||||
{
|
||||
dynamic_cast<QPDF_Array*>(m->obj.getPointer())->getAsVector(result);
|
||||
dynamic_cast<QPDF_Array*>(obj.getPointer())->getAsVector(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -772,7 +736,7 @@ QPDFObjectHandle::setArrayItem(int n, QPDFObjectHandle const& item)
|
||||
{
|
||||
if (isArray())
|
||||
{
|
||||
dynamic_cast<QPDF_Array*>(m->obj.getPointer())->setItem(n, item);
|
||||
dynamic_cast<QPDF_Array*>(obj.getPointer())->setItem(n, item);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -786,7 +750,7 @@ QPDFObjectHandle::setArrayFromVector(std::vector<QPDFObjectHandle> const& items)
|
||||
{
|
||||
if (isArray())
|
||||
{
|
||||
dynamic_cast<QPDF_Array*>(m->obj.getPointer())->setFromVector(items);
|
||||
dynamic_cast<QPDF_Array*>(obj.getPointer())->setFromVector(items);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -800,7 +764,7 @@ QPDFObjectHandle::insertItem(int at, QPDFObjectHandle const& item)
|
||||
{
|
||||
if (isArray())
|
||||
{
|
||||
dynamic_cast<QPDF_Array*>(m->obj.getPointer())->insertItem(at, item);
|
||||
dynamic_cast<QPDF_Array*>(obj.getPointer())->insertItem(at, item);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -814,7 +778,7 @@ QPDFObjectHandle::appendItem(QPDFObjectHandle const& item)
|
||||
{
|
||||
if (isArray())
|
||||
{
|
||||
dynamic_cast<QPDF_Array*>(m->obj.getPointer())->appendItem(item);
|
||||
dynamic_cast<QPDF_Array*>(obj.getPointer())->appendItem(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -828,7 +792,7 @@ QPDFObjectHandle::eraseItem(int at)
|
||||
{
|
||||
if (isArray() && (at < getArrayNItems()) && (at >= 0))
|
||||
{
|
||||
dynamic_cast<QPDF_Array*>(m->obj.getPointer())->eraseItem(at);
|
||||
dynamic_cast<QPDF_Array*>(obj.getPointer())->eraseItem(at);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -852,7 +816,7 @@ QPDFObjectHandle::hasKey(std::string const& key)
|
||||
{
|
||||
if (isDictionary())
|
||||
{
|
||||
return dynamic_cast<QPDF_Dictionary*>(m->obj.getPointer())->hasKey(key);
|
||||
return dynamic_cast<QPDF_Dictionary*>(obj.getPointer())->hasKey(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -870,7 +834,7 @@ QPDFObjectHandle::getKey(std::string const& key)
|
||||
if (isDictionary())
|
||||
{
|
||||
result = dynamic_cast<QPDF_Dictionary*>(
|
||||
m->obj.getPointer())->getKey(key);
|
||||
obj.getPointer())->getKey(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -880,7 +844,7 @@ QPDFObjectHandle::getKey(std::string const& key)
|
||||
result = newNull();
|
||||
QPDF* qpdf = 0;
|
||||
std::string description;
|
||||
if (this->m->obj->getDescription(qpdf, description))
|
||||
if (this->obj->getDescription(qpdf, description))
|
||||
{
|
||||
result.setObjectDescription(
|
||||
qpdf,
|
||||
@ -898,7 +862,7 @@ QPDFObjectHandle::getKeys()
|
||||
std::set<std::string> result;
|
||||
if (isDictionary())
|
||||
{
|
||||
result = dynamic_cast<QPDF_Dictionary*>(m->obj.getPointer())->getKeys();
|
||||
result = dynamic_cast<QPDF_Dictionary*>(obj.getPointer())->getKeys();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -915,7 +879,7 @@ QPDFObjectHandle::getDictAsMap()
|
||||
if (isDictionary())
|
||||
{
|
||||
result = dynamic_cast<QPDF_Dictionary*>(
|
||||
m->obj.getPointer())->getAsMap();
|
||||
obj.getPointer())->getAsMap();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1082,7 +1046,7 @@ QPDF*
|
||||
QPDFObjectHandle::getOwningQPDF()
|
||||
{
|
||||
// Will be null for direct objects
|
||||
return this->m->qpdf;
|
||||
return this->qpdf;
|
||||
}
|
||||
|
||||
// Dictionary mutators
|
||||
@ -1094,7 +1058,7 @@ QPDFObjectHandle::replaceKey(std::string const& key,
|
||||
if (isDictionary())
|
||||
{
|
||||
dynamic_cast<QPDF_Dictionary*>(
|
||||
m->obj.getPointer())->replaceKey(key, value);
|
||||
obj.getPointer())->replaceKey(key, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1108,7 +1072,7 @@ QPDFObjectHandle::removeKey(std::string const& key)
|
||||
{
|
||||
if (isDictionary())
|
||||
{
|
||||
dynamic_cast<QPDF_Dictionary*>(m->obj.getPointer())->removeKey(key);
|
||||
dynamic_cast<QPDF_Dictionary*>(obj.getPointer())->removeKey(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1124,7 +1088,7 @@ QPDFObjectHandle::replaceOrRemoveKey(std::string const& key,
|
||||
if (isDictionary())
|
||||
{
|
||||
dynamic_cast<QPDF_Dictionary*>(
|
||||
m->obj.getPointer())->replaceOrRemoveKey(key, value);
|
||||
obj.getPointer())->replaceOrRemoveKey(key, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1138,21 +1102,21 @@ QPDFObjectHandle
|
||||
QPDFObjectHandle::getDict()
|
||||
{
|
||||
assertStream();
|
||||
return dynamic_cast<QPDF_Stream*>(m->obj.getPointer())->getDict();
|
||||
return dynamic_cast<QPDF_Stream*>(obj.getPointer())->getDict();
|
||||
}
|
||||
|
||||
bool
|
||||
QPDFObjectHandle::isDataModified()
|
||||
{
|
||||
assertStream();
|
||||
return dynamic_cast<QPDF_Stream*>(m->obj.getPointer())->isDataModified();
|
||||
return dynamic_cast<QPDF_Stream*>(obj.getPointer())->isDataModified();
|
||||
}
|
||||
|
||||
void
|
||||
QPDFObjectHandle::replaceDict(QPDFObjectHandle new_dict)
|
||||
{
|
||||
assertStream();
|
||||
dynamic_cast<QPDF_Stream*>(m->obj.getPointer())->replaceDict(new_dict);
|
||||
dynamic_cast<QPDF_Stream*>(obj.getPointer())->replaceDict(new_dict);
|
||||
}
|
||||
|
||||
PointerHolder<Buffer>
|
||||
@ -1160,14 +1124,14 @@ QPDFObjectHandle::getStreamData(qpdf_stream_decode_level_e level)
|
||||
{
|
||||
assertStream();
|
||||
return dynamic_cast<QPDF_Stream*>(
|
||||
m->obj.getPointer())->getStreamData(level);
|
||||
obj.getPointer())->getStreamData(level);
|
||||
}
|
||||
|
||||
PointerHolder<Buffer>
|
||||
QPDFObjectHandle::getRawStreamData()
|
||||
{
|
||||
assertStream();
|
||||
return dynamic_cast<QPDF_Stream*>(m->obj.getPointer())->getRawStreamData();
|
||||
return dynamic_cast<QPDF_Stream*>(obj.getPointer())->getRawStreamData();
|
||||
}
|
||||
|
||||
bool
|
||||
@ -1177,7 +1141,7 @@ QPDFObjectHandle::pipeStreamData(Pipeline* p,
|
||||
bool suppress_warnings, bool will_retry)
|
||||
{
|
||||
assertStream();
|
||||
return dynamic_cast<QPDF_Stream*>(m->obj.getPointer())->pipeStreamData(
|
||||
return dynamic_cast<QPDF_Stream*>(obj.getPointer())->pipeStreamData(
|
||||
p, encode_flags, decode_level, suppress_warnings, will_retry);
|
||||
}
|
||||
|
||||
@ -1208,7 +1172,7 @@ QPDFObjectHandle::replaceStreamData(PointerHolder<Buffer> data,
|
||||
QPDFObjectHandle const& decode_parms)
|
||||
{
|
||||
assertStream();
|
||||
dynamic_cast<QPDF_Stream*>(m->obj.getPointer())->replaceStreamData(
|
||||
dynamic_cast<QPDF_Stream*>(obj.getPointer())->replaceStreamData(
|
||||
data, filter, decode_parms);
|
||||
}
|
||||
|
||||
@ -1221,7 +1185,7 @@ QPDFObjectHandle::replaceStreamData(std::string const& data,
|
||||
PointerHolder<Buffer> b = new Buffer(data.length());
|
||||
unsigned char* bp = b->getBuffer();
|
||||
memcpy(bp, data.c_str(), data.length());
|
||||
dynamic_cast<QPDF_Stream*>(m->obj.getPointer())->replaceStreamData(
|
||||
dynamic_cast<QPDF_Stream*>(obj.getPointer())->replaceStreamData(
|
||||
b, filter, decode_parms);
|
||||
}
|
||||
|
||||
@ -1231,26 +1195,26 @@ QPDFObjectHandle::replaceStreamData(PointerHolder<StreamDataProvider> provider,
|
||||
QPDFObjectHandle const& decode_parms)
|
||||
{
|
||||
assertStream();
|
||||
dynamic_cast<QPDF_Stream*>(m->obj.getPointer())->replaceStreamData(
|
||||
dynamic_cast<QPDF_Stream*>(obj.getPointer())->replaceStreamData(
|
||||
provider, filter, decode_parms);
|
||||
}
|
||||
|
||||
QPDFObjGen
|
||||
QPDFObjectHandle::getObjGen() const
|
||||
{
|
||||
return QPDFObjGen(this->m->objid, this->m->generation);
|
||||
return QPDFObjGen(this->objid, this->generation);
|
||||
}
|
||||
|
||||
int
|
||||
QPDFObjectHandle::getObjectID() const
|
||||
{
|
||||
return this->m->objid;
|
||||
return this->objid;
|
||||
}
|
||||
|
||||
int
|
||||
QPDFObjectHandle::getGeneration() const
|
||||
{
|
||||
return this->m->generation;
|
||||
return this->generation;
|
||||
}
|
||||
|
||||
std::map<std::string, QPDFObjectHandle>
|
||||
@ -1352,8 +1316,8 @@ std::vector<QPDFObjectHandle>
|
||||
QPDFObjectHandle::getPageContents()
|
||||
{
|
||||
std::string description = "page object " +
|
||||
QUtil::int_to_string(this->m->objid) + " " +
|
||||
QUtil::int_to_string(this->m->generation);
|
||||
QUtil::int_to_string(this->objid) + " " +
|
||||
QUtil::int_to_string(this->generation);
|
||||
std::string all_description;
|
||||
return this->getKey("/Contents").arrayOrStreamToStreamArray(
|
||||
description, all_description);
|
||||
@ -1480,8 +1444,8 @@ QPDFObjectHandle::unparse()
|
||||
std::string result;
|
||||
if (this->isIndirect())
|
||||
{
|
||||
result = QUtil::int_to_string(this->m->objid) + " " +
|
||||
QUtil::int_to_string(this->m->generation) + " R";
|
||||
result = QUtil::int_to_string(this->objid) + " " +
|
||||
QUtil::int_to_string(this->generation) + " R";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1493,13 +1457,13 @@ QPDFObjectHandle::unparse()
|
||||
std::string
|
||||
QPDFObjectHandle::unparseResolved()
|
||||
{
|
||||
if (this->m->reserved)
|
||||
if (this->reserved)
|
||||
{
|
||||
throw std::logic_error(
|
||||
"QPDFObjectHandle: attempting to unparse a reserved object");
|
||||
}
|
||||
dereference();
|
||||
return this->m->obj->unparse();
|
||||
return this->obj->unparse();
|
||||
}
|
||||
|
||||
std::string
|
||||
@ -1508,7 +1472,7 @@ QPDFObjectHandle::unparseBinary()
|
||||
if (this->isString())
|
||||
{
|
||||
return dynamic_cast<QPDF_String*>(
|
||||
this->m->obj.getPointer())->unparse(true);
|
||||
this->obj.getPointer())->unparse(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1525,13 +1489,13 @@ QPDFObjectHandle::getJSON(bool dereference_indirect)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this->m->reserved)
|
||||
if (this->reserved)
|
||||
{
|
||||
throw std::logic_error(
|
||||
"QPDFObjectHandle: attempting to unparse a reserved object");
|
||||
}
|
||||
dereference();
|
||||
return this->m->obj->getJSON();
|
||||
return this->obj->getJSON();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1577,8 +1541,8 @@ void
|
||||
QPDFObjectHandle::pipePageContents(Pipeline* p)
|
||||
{
|
||||
std::string description = "page object " +
|
||||
QUtil::int_to_string(this->m->objid) + " " +
|
||||
QUtil::int_to_string(this->m->generation);
|
||||
QUtil::int_to_string(this->objid) + " " +
|
||||
QUtil::int_to_string(this->generation);
|
||||
std::string all_description;
|
||||
this->getKey("/Contents").pipeContentStreams(
|
||||
p, description, all_description);
|
||||
@ -1613,8 +1577,8 @@ void
|
||||
QPDFObjectHandle::parsePageContents(ParserCallbacks* callbacks)
|
||||
{
|
||||
std::string description = "page object " +
|
||||
QUtil::int_to_string(this->m->objid) + " " +
|
||||
QUtil::int_to_string(this->m->generation);
|
||||
QUtil::int_to_string(this->objid) + " " +
|
||||
QUtil::int_to_string(this->generation);
|
||||
this->getKey("/Contents").parseContentStream_internal(
|
||||
description, callbacks);
|
||||
}
|
||||
@ -1623,8 +1587,8 @@ void
|
||||
QPDFObjectHandle::filterPageContents(TokenFilter* filter, Pipeline* next)
|
||||
{
|
||||
std::string description = "token filter for page object " +
|
||||
QUtil::int_to_string(this->m->objid) + " " +
|
||||
QUtil::int_to_string(this->m->generation);
|
||||
QUtil::int_to_string(this->objid) + " " +
|
||||
QUtil::int_to_string(this->generation);
|
||||
Pl_QPDFTokenizer token_pipeline(description.c_str(), filter, next);
|
||||
this->pipePageContents(&token_pipeline);
|
||||
}
|
||||
@ -1633,8 +1597,8 @@ void
|
||||
QPDFObjectHandle::filterAsContents(TokenFilter* filter, Pipeline* next)
|
||||
{
|
||||
std::string description = "token filter for object " +
|
||||
QUtil::int_to_string(this->m->objid) + " " +
|
||||
QUtil::int_to_string(this->m->generation);
|
||||
QUtil::int_to_string(this->objid) + " " +
|
||||
QUtil::int_to_string(this->generation);
|
||||
Pl_QPDFTokenizer token_pipeline(description.c_str(), filter, next);
|
||||
this->pipeStreamData(&token_pipeline, 0, qpdf_dl_specialized);
|
||||
}
|
||||
@ -1745,7 +1709,7 @@ QPDFObjectHandle::addTokenFilter(PointerHolder<TokenFilter> filter)
|
||||
{
|
||||
assertStream();
|
||||
return dynamic_cast<QPDF_Stream*>(
|
||||
m->obj.getPointer())->addTokenFilter(filter);
|
||||
obj.getPointer())->addTokenFilter(filter);
|
||||
}
|
||||
|
||||
QPDFObjectHandle
|
||||
@ -2258,15 +2222,15 @@ qpdf_offset_t
|
||||
QPDFObjectHandle::getParsedOffset()
|
||||
{
|
||||
dereference();
|
||||
return this->m->obj->getParsedOffset();
|
||||
return this->obj->getParsedOffset();
|
||||
}
|
||||
|
||||
void
|
||||
QPDFObjectHandle::setParsedOffset(qpdf_offset_t offset)
|
||||
{
|
||||
if (this->m->obj.getPointer())
|
||||
if (this->obj.getPointer())
|
||||
{
|
||||
this->m->obj->setParsedOffset(offset);
|
||||
this->obj->setParsedOffset(offset);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2438,7 +2402,7 @@ QPDFObjectHandle::newStream(QPDF* qpdf)
|
||||
new QPDF_Stream(qpdf, 0, 0, stream_dict, 0, 0)));
|
||||
result.dereference();
|
||||
QPDF_Stream* stream =
|
||||
dynamic_cast<QPDF_Stream*>(result.m->obj.getPointer());
|
||||
dynamic_cast<QPDF_Stream*>(result.obj.getPointer());
|
||||
stream->setObjGen(result.getObjectID(), result.getGeneration());
|
||||
return result;
|
||||
}
|
||||
@ -2469,8 +2433,8 @@ QPDFObjectHandle::newReserved(QPDF* qpdf)
|
||||
QPDFObjectHandle reserved = qpdf->makeIndirectObject(
|
||||
QPDFObjectHandle(new QPDF_Reserved()));
|
||||
QPDFObjectHandle result =
|
||||
newIndirect(qpdf, reserved.m->objid, reserved.m->generation);
|
||||
result.m->reserved = true;
|
||||
newIndirect(qpdf, reserved.objid, reserved.generation);
|
||||
result.reserved = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -2478,18 +2442,18 @@ void
|
||||
QPDFObjectHandle::setObjectDescription(QPDF* owning_qpdf,
|
||||
std::string const& object_description)
|
||||
{
|
||||
if (isInitialized() && this->m->obj.getPointer())
|
||||
if (isInitialized() && this->obj.getPointer())
|
||||
{
|
||||
this->m->obj->setDescription(owning_qpdf, object_description);
|
||||
this->obj->setDescription(owning_qpdf, object_description);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
QPDFObjectHandle::hasObjectDescription()
|
||||
{
|
||||
if (isInitialized() && this->m->obj.getPointer())
|
||||
if (isInitialized() && this->obj.getPointer())
|
||||
{
|
||||
return this->m->obj->hasDescription();
|
||||
return this->obj->hasDescription();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -2511,7 +2475,7 @@ QPDFObjectHandle::shallowCopy()
|
||||
{
|
||||
QTC::TC("qpdf", "QPDFObjectHandle shallow copy array");
|
||||
// No newArray for shallow copying the sparse array
|
||||
QPDF_Array* arr = dynamic_cast<QPDF_Array*>(m->obj.getPointer());
|
||||
QPDF_Array* arr = dynamic_cast<QPDF_Array*>(obj.getPointer());
|
||||
new_obj = QPDFObjectHandle(
|
||||
new QPDF_Array(arr->getElementsForShallowCopy()));
|
||||
}
|
||||
@ -2544,7 +2508,7 @@ QPDFObjectHandle::copyObject(std::set<QPDFObjGen>& visited,
|
||||
"attempt to make a stream into a direct object");
|
||||
}
|
||||
|
||||
QPDFObjGen cur_og(this->m->objid, this->m->generation);
|
||||
QPDFObjGen cur_og(this->objid, this->generation);
|
||||
if (cur_og.getObj() != 0)
|
||||
{
|
||||
if (visited.count(cur_og))
|
||||
@ -2565,9 +2529,9 @@ QPDFObjectHandle::copyObject(std::set<QPDFObjGen>& visited,
|
||||
}
|
||||
|
||||
dereference();
|
||||
this->m->qpdf = 0;
|
||||
this->m->objid = 0;
|
||||
this->m->generation = 0;
|
||||
this->qpdf = 0;
|
||||
this->objid = 0;
|
||||
this->generation = 0;
|
||||
|
||||
PointerHolder<QPDFObject> new_obj;
|
||||
|
||||
@ -2638,7 +2602,7 @@ QPDFObjectHandle::copyObject(std::set<QPDFObjGen>& visited,
|
||||
"unknown object type");
|
||||
}
|
||||
|
||||
this->m->obj = new_obj;
|
||||
this->obj = new_obj;
|
||||
|
||||
if (cur_og.getObj())
|
||||
{
|
||||
@ -2656,7 +2620,7 @@ QPDFObjectHandle::makeDirect()
|
||||
void
|
||||
QPDFObjectHandle::assertInitialized() const
|
||||
{
|
||||
if (! this->m->initialized)
|
||||
if (! this->initialized)
|
||||
{
|
||||
throw std::logic_error("operation attempted on uninitialized "
|
||||
"QPDFObjectHandle");
|
||||
@ -2669,7 +2633,7 @@ QPDFObjectHandle::typeWarning(char const* expected_type,
|
||||
{
|
||||
QPDF* context = 0;
|
||||
std::string description;
|
||||
if (this->m->obj->getDescription(context, description))
|
||||
if (this->obj->getDescription(context, description))
|
||||
{
|
||||
warn(context,
|
||||
QPDFExc(
|
||||
@ -2691,7 +2655,7 @@ QPDFObjectHandle::warnIfPossible(std::string const& warning,
|
||||
{
|
||||
QPDF* context = 0;
|
||||
std::string description;
|
||||
if (this->m->obj->getDescription(context, description))
|
||||
if (this->obj->getDescription(context, description))
|
||||
{
|
||||
warn(context,
|
||||
QPDFExc(
|
||||
@ -2863,15 +2827,15 @@ QPDFObjectHandle::assertPageObject()
|
||||
void
|
||||
QPDFObjectHandle::dereference()
|
||||
{
|
||||
if (this->m->obj.getPointer() == 0)
|
||||
if (this->obj.getPointer() == 0)
|
||||
{
|
||||
PointerHolder<QPDFObject> obj = QPDF::Resolver::resolve(
|
||||
this->m->qpdf, this->m->objid, this->m->generation);
|
||||
this->qpdf, this->objid, this->generation);
|
||||
if (obj.getPointer() == 0)
|
||||
{
|
||||
// QPDF::resolve never returns an uninitialized object, but
|
||||
// check just in case.
|
||||
this->m->obj = new QPDF_Null();
|
||||
this->obj = new QPDF_Null();
|
||||
}
|
||||
else if (dynamic_cast<QPDF_Reserved*>(obj.getPointer()))
|
||||
{
|
||||
@ -2879,8 +2843,8 @@ QPDFObjectHandle::dereference()
|
||||
}
|
||||
else
|
||||
{
|
||||
this->m->reserved = false;
|
||||
this->m->obj = obj;
|
||||
this->reserved = false;
|
||||
this->obj = obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user